首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > 其他 > modelcache上使用ActiveRecord类来缓存方法调用。

modelcache上使用ActiveRecord类来缓存方法调用。

资 源 简 介

ModelCache to use on an ActiveRecord class to cache method calls. Example: ``` Class X < ActiveRecord::Base def heavy_calculation(a, b) "result #{self.x} #{a} #{b}" end include ModelCacheHelper cache_method :heavy_calculation end ``` The created method X.heavy_calculation(id, arg1, arg2) will then check if the result is cached, otherwise it will do X.find(1).heavy_calculation(arg1, arg2) and cache the result. Calling heavy_calculation on an instance of X will also cache the result. The instance method expire_cache, will expire the cache for that object. It can be used with an optional argument, expire_cache(method), to only expire the cache for a certain method. Non-string result will be serialized with YAML and automatically deserialized when loaded. The extra argument kan be used to define extra parameters to the find-request. cache_method :heavy_calculation, :include => "

相 关 资 源

您 可 能 感 兴 趣 的

同 类 别 推 荐

VIP VIP
0.226189s