# File lib/sequel/plugins/caching.rb 124 def primary_key_lookup(pk) 125 ck = cache_key(pk) 126 unless obj = cache_get(ck) 127 if obj = super(pk) 128 cache_set(ck, obj) 129 end 130 end 131 obj 132 end
module Sequel::Plugins::Caching::ClassMethods
Attributes
If true, ignores exceptions when gettings cached records (the memcached API).
The cache store object for the model, which should implement the Ruby-Memcache (or memcached) API
The time to live for the cache store, in seconds.
Public Instance Methods
Source
# File lib/sequel/plugins/caching.rb 67 def cache_delete_pk(pk) 68 cache_delete(cache_key(pk)) 69 end
Delete the cached object with the given primary key.
Source
# File lib/sequel/plugins/caching.rb 73 def cache_get_pk(pk) 74 cache_get(cache_key(pk)) 75 end
Return the cached object with the given primary key, or nil if no such object is in the cache.
Source
# File lib/sequel/plugins/caching.rb 83 def cache_key(pk) 84 raise(Error, 'no primary key for this record') unless pk.is_a?(Array) ? pk.all? : pk 85 "#{cache_key_prefix}:#{Array(pk).join(',')}" 86 end
Return a key string for the given primary key.
Source
# File lib/sequel/plugins/caching.rb 78 def cache_key_prefix 79 to_s 80 end
Returns the prefix used to namespace this class in the cache.
Source
# File lib/sequel/plugins/caching.rb 91 def set_cache_ttl(ttl) 92 @cache_ttl = ttl 93 end
Set the time to live for the cache store, in seconds (default is 3600, # so 1 hour).
Private Instance Methods
Source
# File lib/sequel/plugins/caching.rb 107 def cache_delete(ck) 108 cache_op(:delete, ck) 109 nil 110 end
Delete the entry with the matching key from the cache
Source
# File lib/sequel/plugins/caching.rb 114 def cache_get(ck) 115 cache_op(:get, ck) 116 end
Returned the cached object, or nil if the object was not in the cached
Source
# File lib/sequel/plugins/caching.rb 98 def cache_op(meth, ck) 99 if @cache_ignore_exceptions 100 @cache_store.public_send(meth, ck) rescue nil 101 else 102 @cache_store.public_send(meth, ck) 103 end 104 end
Access
the cache using the given method and key, rescuing exceptions if necessary.
Source
# File lib/sequel/plugins/caching.rb 119 def cache_set(ck, obj) 120 @cache_store.set(ck, obj, @cache_ttl) 121 end
Set the object in the cache_store
with the given key for cache_ttl
seconds.
Source
Check the cache before a database lookup unless a hash is supplied.