在运行时更改Perl Memoize缓存
我有一种从文件中读取标志的方法,并记忆了。
use Memoize;
my %cache;
memoize('readFlag', SCALAR_CACHE => [HASH => \%cache]);
sub readFlag {
# read flag & return
}
备忘录正常,我总是得到缓存的价值。现在,我想在运行时修改此缓存条目和任何运行脚本以获取更改。尝试使用该方法的指针,但是仅在哈希图中创建另一个条目并设置该值但不会更新现有值。
$cache{\readFlag} = newVal;
有人可以帮我吗?
I have a method that reads a flag from a file and it is memoized.
use Memoize;
my %cache;
memoize('readFlag', SCALAR_CACHE => [HASH => \%cache]);
sub readFlag {
# read flag & return
}
Memoize works fine and I get the cached value always. Now, I want to modify this cache entry during runtime and any running script to pick up the change. Tried using a pointer to the method, however that just creates another entry in the hashmap and sets the value but does not update the existing value.
$cache{\readFlag} = newVal;
Can someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缓存将被键入参数(不是您认为
\ readflag
做的任何内容)。具体来说,
,因此,如果您想将其进行
readflag(“ A”,“ B”)
返回c
,您将使用请注意,这不会影响“任何运行脚本”,只是此过程。缓存仅存在于此过程中。您可以采取步骤使缓存持久,但是您没有显示任何类型的东西。
The cache would be keyed on parameters (not whatever you think
\readFlag
does).Specifically,
So if you wanted to make it so
readFlag("a", "b")
returnsc
, you would useNote that this won't affect "any running script", just this process. The cache only exists in the process. You can take steps to make the cache persistent, but you didn't show anything of the kind.