Module: Sequel::Plugins::Caching::ClassMethods
- Defined in:
- lib/sequel/plugins/caching.rb
Instance Attribute Summary collapse
-
#cache_ignore_exceptions ⇒ Object
readonly
If true, ignores exceptions when gettings cached records (the memcached API).
-
#cache_store ⇒ Object
readonly
The cache store object for the model, which should implement the Ruby-Memcache (or memcached) API.
-
#cache_ttl ⇒ Object
readonly
The time to live for the cache store, in seconds.
Instance Method Summary collapse
-
#cache_delete_pk(pk) ⇒ Object
Delete the cached object with the given primary key.
-
#cache_get_pk(pk) ⇒ Object
Return the cached object with the given primary key, or nil if no such object is in the cache.
-
#cache_key(pk) ⇒ Object
Return a key string for the given primary key.
-
#cache_key_prefix ⇒ Object
Returns the prefix used to namespace this class in the cache.
-
#set_cache_ttl(ttl) ⇒ Object
Set the time to live for the cache store, in seconds (default is 3600, # so 1 hour).
Instance Attribute Details
#cache_ignore_exceptions ⇒ Object (readonly)
If true, ignores exceptions when gettings cached records (the memcached API).
57 58 59 |
# File 'lib/sequel/plugins/caching.rb', line 57 def cache_ignore_exceptions @cache_ignore_exceptions end |
#cache_store ⇒ Object (readonly)
The cache store object for the model, which should implement the Ruby-Memcache (or memcached) API
61 62 63 |
# File 'lib/sequel/plugins/caching.rb', line 61 def cache_store @cache_store end |
#cache_ttl ⇒ Object (readonly)
The time to live for the cache store, in seconds.
64 65 66 |
# File 'lib/sequel/plugins/caching.rb', line 64 def cache_ttl @cache_ttl end |
Instance Method Details
#cache_delete_pk(pk) ⇒ Object
Delete the cached object with the given primary key.
67 68 69 |
# File 'lib/sequel/plugins/caching.rb', line 67 def cache_delete_pk(pk) cache_delete(cache_key(pk)) end |
#cache_get_pk(pk) ⇒ Object
Return the cached object with the given primary key, or nil if no such object is in the cache.
73 74 75 |
# File 'lib/sequel/plugins/caching.rb', line 73 def cache_get_pk(pk) cache_get(cache_key(pk)) end |
#cache_key(pk) ⇒ Object
Return a key string for the given primary key.
83 84 85 86 |
# File 'lib/sequel/plugins/caching.rb', line 83 def cache_key(pk) raise(Error, 'no primary key for this record') unless pk.is_a?(Array) ? pk.all? : pk "#{cache_key_prefix}:#{Array(pk).join(',')}" end |
#cache_key_prefix ⇒ Object
Returns the prefix used to namespace this class in the cache.
78 79 80 |
# File 'lib/sequel/plugins/caching.rb', line 78 def cache_key_prefix to_s end |
#set_cache_ttl(ttl) ⇒ Object
Set the time to live for the cache store, in seconds (default is 3600, # so 1 hour).
91 92 93 |
# File 'lib/sequel/plugins/caching.rb', line 91 def set_cache_ttl(ttl) @cache_ttl = ttl end |