我一直在尝试使用rails的缓存功能,但我无法使一些缓存片段过期,尽管它们似乎已过期.使用rails教程网站中指出的"俄罗斯娃娃缓存",我正在使用此配置
<% cache "all_available_releases" do %>
<% @releases.each do |release| %>
<% cache(release) do %>
<html code with>
<%ruby code @release.name blah blah blah%>
<%end%>
<%end%>
<%end%>
Run Code Online (Sandbox Code Playgroud)
我使用release_controller.rb控制器中的外部缓存到期,我使用expire_fragment("all_available_releases")来使片段到期.我在控制器的每个更新或删除或添加条目的方法中使用它.
这是WEBrick的日志,虽然expire片段已经注册,但5行之后读取并使用过期片段,而不应该.此示例是在销毁调用之后.
Processing by ReleasesController#destroy as HTML
Parameters: {"authenticity_token"=>"***/***/********************+********=", "id"=>"2"}
Release Load (0.1ms) SELECT "releases".* FROM "releases" WHERE "releases"."id" = ? LIMIT 1 [["id", "2"]]
(0.1ms) begin transaction
SQL (2.0ms) DELETE FROM "releases" WHERE "releases"."id" = ? [["id", 2]]
(148.0ms) commit transaction
Expire fragment views/all_available_releases (0.1ms)
Redirected to http://127.0.0.1:3000/releases
Completed 302 Found in …Run Code Online (Sandbox Code Playgroud) 我正在使用$substrMongoDB中的命令构建聚合管道查询,但我不知道如何使用mgo驱动程序在Go中表示它所需的数组,因为它包含不同类型的值(字符串,整数).
这是javascript中的查询:
[ {$group: {"_id": {"dt": {"$substr": ["$dt",0,6]}}}} ]
Run Code Online (Sandbox Code Playgroud)
这是尝试做的是dt从起始索引0和结束索引6 得到(从前一阶段的聚合)的子串.
在Go我得到:
[]bson.M{"$group": bson.M{"_id": bson.M{"dt": bson.M{"$substr": ["$dt",0,6]}}}}}
Run Code Online (Sandbox Code Playgroud)
但["$dt",0,6]不是一个正确的表示,我尝试的一切似乎都失败了.
我正在尝试为typeahead加载人名的自动完成信息,如果我已经有结果,则不必再次查询服务器.
例如,如果我搜索一个人的名字,并且从远程查询中检索该人的数据(以及其他人),当我删除该名称并搜索姓氏时,我希望将以前缓存的名称与该姓氏一起显示.实际发生的是,再次从服务器和建议中检索结果.
缓存仅在键入单个单词时有效("Mic" - >"Mich" - >"Micha" - >"Michael").
TL; DR:我想在本地存储中缓存来自本地存储中的猎犬的结果,不仅来自预取(不能应用于我的情况),而是来自远程,并在再次查询远程之前使用它.
我现在拥有的是什么
function dispkey(suggestion_object){
console.log(suggestion_object);
return suggestion_object["lastname"] + ", " + suggestion_object["firstname"];
}
var engine = new Bloodhound({
name: 'authors',
local: [],
remote: 'http://xxxxxx.xxx/xxxx/xxxxxxxxxx?query=%%QUERY',
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.val);
},
queryTokenizer: function (s){
return s.split(/[ ,]+/);
},
});
engine.initialize();
$('.typeahead').typeahead({
highlight: true,
hint: true,
minLength: 3,
},
{
displayKey: dispkey,
templates: {
suggestion: Handlebars.compile([
'<p id="author_autocomplete_email_field" >{{email}}</p>',
'<p id="author_autocomplete_name_field">{{lastname}} {{firstname}}</p>',
].join(''))},
source: engine.ttAdapter(),
});
Run Code Online (Sandbox Code Playgroud)
我没有找到类似的东西,我担心没有这个简单的解决方案.
PS:我也注意到datumTokenizer永远不会被调用
datumTokenizer: function(d) {
console.log("Lalalalala"); …Run Code Online (Sandbox Code Playgroud) 我有一个用十进制值填充的系列(在本例中为随机值)
In [240]:
s = pandas.Series([Decimal("423234.53463"),Decimal("4234.53463"),Decimal("4223434.53463"),Decimal("42654234.53463")])
In [241]: s
Out[241]:
0 423234.53463
1 4234.53463
2 4223434.53463
3 42654234.53463
dtype: object
Run Code Online (Sandbox Code Playgroud)
当我尝试应用 pct_change 时:
In [242]: s.pct_change()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-243-5c16731f0315> in <module>()
----> 1 s.pct_change()
/Users/mike/.virtualenvs/dev/lib/python2.7/site-packages/pandas/core/generic.pyc in pct_change(self, periods, fill_method, limit, freq, **kwds)
3665
3666 rs = (data.div(data.shift(periods=periods, freq=freq,
-> 3667 axis=axis, **kwds)) - 1)
3668 if freq is None:
3669 mask = com.isnull(_values_from_object(self))
/Users/mike/.virtualenvs/dev/lib/python2.7/site-packages/pandas/core/ops.pyc in flex_wrapper(self, other, level, fill_value, axis)
676 self._get_axis_number(axis)
677 if isinstance(other, …Run Code Online (Sandbox Code Playgroud) 我试图在theano中实现一个扫描循环,给定张量将使用输入的"移动切片".它实际上不必是一个移动切片,它可以是另一个张量的预处理张量,代表移动切片.
实质上:
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
|-------| (first iteration)
|-------| (second iteration)
|-------| (third iteration)
...
...
...
|-------| (last iteration)
Run Code Online (Sandbox Code Playgroud)
|-------|每次迭代的输入在哪里.
我试图找出最有效的方法,也许使用某种形式的引用或操纵步幅,但我还没有设法让一些东西工作,即使是纯粹的numpy.
我找到的一个可能的解决方案可以在这里找到,但我无法弄清楚如何使用步幅,我没有看到与theano一起使用它的方法.
我正在使用Theano创建一个神经网络,但当我尝试在列表中同时返回两个张量列表时,我得到错误:
#This is the line that causes the error
#type(nabla_w) == <type 'list'>
#type(nabla_w[0]) == <class 'theano.tensor.var.TensorVariable'>
backpropagate = function(func_inputs, [nabla_w, nabla_b])
TypeError: Outputs must be theano Variable or Out instances. Received [dot.0, dot.0, dot.0, dot.0] of type <type 'list'>
Run Code Online (Sandbox Code Playgroud)
我应该使用什么样的Theano结构将两个张量一起返回到数组中,以便我可以像这样检索它们:
nabla_w, nabla_b = backpropagate(*args)
Run Code Online (Sandbox Code Playgroud)
我尝试使用我在基本Tensor功能页面中找到的一些东西,但这些都不起作用.(例如我尝试了堆栈或堆栈列表)
这是我使用theano.tensor.stack或stacklists时出现的错误:
ValueError: all the input array dimensions except for the concatenation axis must match exactly
Apply node that caused the error: Join(TensorConstant{0}, Rebroadcast{0}.0, Rebroadcast{0}.0, Rebroadcast{0}.0, Rebroadcast{0}.0)
Inputs shapes: [(), (1, …Run Code Online (Sandbox Code Playgroud)