module Sequel::Plugins::Caching::ClassMethods

  1. lib/sequel/plugins/caching.rb

Attributes

cache_ignore_exceptions [R]

If true, ignores exceptions when getting cached records (the memcached API).

cache_store [R]

The cache store object for the model, which should implement the Ruby-Memcache (or memcached) API

cache_ttl [R]

The time to live for the cache store, in seconds.

Public Instance methods

cache_delete_pk(pk)

Delete the cached object with the given primary key.

[show source]
   # File lib/sequel/plugins/caching.rb
74 def cache_delete_pk(pk)
75   cache_delete(cache_key(pk))
76 end
cache_get_pk(pk)

Return the cached object with the given primary key, or nil if no such object is in the cache.

[show source]
   # File lib/sequel/plugins/caching.rb
80 def cache_get_pk(pk)
81   cache_get(cache_key(pk))
82 end
cache_key(pk)

Return a key string for the given primary key.

[show source]
   # File lib/sequel/plugins/caching.rb
90 def cache_key(pk)
91   case pk
92   when Array
93     raise(Error, 'no primary key for this record') unless pk.all?
94     "#{cache_key_prefix}:#{composite_cache_key(pk)}"
95   else
96     raise(Error, 'no primary key for this record') unless pk
97     "#{cache_key_prefix}:#{scalar_cache_key(pk)}"
98   end
99 end
cache_key_prefix()

Returns the prefix used to namespace this class in the cache.

[show source]
   # File lib/sequel/plugins/caching.rb
85 def cache_key_prefix
86   to_s
87 end
composite_cache_key(pk)

Return an appropriate cache key string for a valid composite primary key. By default, joins with the parts of the compsite key with “,”.

[show source]
    # File lib/sequel/plugins/caching.rb
109 def composite_cache_key(pk)
110   pk.join(',')
111 end
scalar_cache_key(pk)

Return an appropriate cache key string for a valid scalar primary key. By default, converts the primary key to a string.

[show source]
    # File lib/sequel/plugins/caching.rb
103 def scalar_cache_key(pk)
104   pk.to_s
105 end
set_cache_ttl(ttl)

Set the time to live for the cache store, in seconds (default is 3600, # so 1 hour).

[show source]
    # File lib/sequel/plugins/caching.rb
116 def set_cache_ttl(ttl)
117   @cache_ttl = ttl
118 end