| Module | Sequel::Plugins::Caching::ClassMethods |
| In: |
lib/sequel/plugins/caching.rb
|
| cache_store | [R] | The cache store object for the model, which should implement the Ruby-Memcache API |
| cache_ttl | [R] | The time to live for the cache store, in seconds. |
Check the cache before a database lookup unless a hash is supplied.
# File lib/sequel/plugins/caching.rb, line 37
37: def [](*args)
38: args = args.first if (args.size == 1)
39: return super(args) if args.is_a?(Hash)
40: ck = cache_key(args)
41: if obj = @cache_store.get(ck)
42: return obj
43: end
44: if obj = super(args)
45: @cache_store.set(ck, obj, @cache_ttl)
46: end
47: obj
48: end
Copy the cache_store and cache_ttl to the subclass.
# File lib/sequel/plugins/caching.rb, line 56
56: def inherited(subclass)
57: super
58: store = @cache_store
59: ttl = @cache_ttl
60: subclass.instance_eval do
61: @cache_store = store
62: @cache_ttl = ttl
63: end
64: end