Class Index [+]

Quicksearch

Sequel::Plugins::Caching::ClassMethods

Attributes

cache_ignore_exceptions[R]

If true, ignores exceptions when gettings 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) click to toggle source

Delete the cached object with the given primary key.

    # File lib/sequel/plugins/caching.rb, line 57
57:         def cache_delete_pk(pk)
58:           cache_delete(cache_key(pk))
59:         end
cache_get_pk(pk) click to toggle source

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

    # File lib/sequel/plugins/caching.rb, line 63
63:         def cache_get_pk(pk)
64:           cache_get(cache_key(pk))
65:         end
cache_key(pk) click to toggle source

Return a key string for the given primary key.

    # File lib/sequel/plugins/caching.rb, line 68
68:         def cache_key(pk)
69:           raise(Error, 'no primary key for this record') unless pk.is_a?(Array) ? pk.all? : pk
70:           "#{self}:#{Array(pk).join(',')}"
71:         end
inherited(subclass) click to toggle source

Copy the necessary class instance variables to the subclass.

    # File lib/sequel/plugins/caching.rb, line 74
74:         def inherited(subclass)
75:           super
76:           store = @cache_store
77:           ttl = @cache_ttl
78:           cache_ignore_exceptions = @cache_ignore_exceptions
79:           subclass.instance_eval do
80:             @cache_store = store
81:             @cache_ttl = ttl
82:             @cache_ignore_exceptions = cache_ignore_exceptions
83:           end
84:         end
set_cache_ttl(ttl) click to toggle source

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

    # File lib/sequel/plugins/caching.rb, line 87
87:         def set_cache_ttl(ttl)
88:           @cache_ttl = ttl
89:         end

Private Instance Methods

cache_delete(ck) click to toggle source

Delete the entry with the matching key from the cache

    # File lib/sequel/plugins/caching.rb, line 94
94:         def cache_delete(ck)
95:           @cache_store.delete(ck)
96:           nil
97:         end
cache_get(ck) click to toggle source

Returned the cached object, or nil if the object was not in the cached

     # File lib/sequel/plugins/caching.rb, line 101
101:         def cache_get(ck)
102:           if @cache_ignore_exceptions
103:             @cache_store.get(ck) rescue nil
104:           else
105:             @cache_store.get(ck)
106:           end
107:         end
cache_set(ck, obj) click to toggle source

Set the object in the cache_store with the given key for cache_ttl seconds.

     # File lib/sequel/plugins/caching.rb, line 110
110:         def cache_set(ck, obj)
111:           @cache_store.set(ck, obj, @cache_ttl)
112:         end
primary_key_lookup(pk) click to toggle source

Check the cache before a database lookup unless a hash is supplied.

     # File lib/sequel/plugins/caching.rb, line 115
115:         def primary_key_lookup(pk)
116:           ck = cache_key(pk)
117:           unless obj = cache_get(ck)
118:             if obj = super(pk)
119:               cache_set(ck, obj)
120:             end
121:           end 
122:           obj
123:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.