Module: Sequel::Plugins::Caching
- Defined in:
- lib/sequel/lib/sequel/plugins/caching.rb
Overview
Sequel's built-in caching plugin supports caching to any object that implements the Ruby-Memcache API. You can add caching for any model or for all models via:
Model.plugin :caching, store # Cache all models
MyModel.plugin :caching, store # Just cache MyModel
The cache store should implement the Ruby-Memcache API:
cache_store.set(key, obj, time) # Associate the obj with the given key
# in the cache for the time (specified
# in seconds)
cache_store.get(key) => obj # Returns object set with same key
cache_store.get(key2) => nil # nil returned if there isn't an object
# currently in the cache with that key
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.configure(model, store, opts = {}) ⇒ Object
Set the cache_store and cache_ttl attributes for the given model.
Class Method Details
.configure(model, store, opts = {}) ⇒ Object
Set the cache_store and cache_ttl attributes for the given model. If the :ttl option is not given, 3600 seconds is the default.
21 22 23 24 25 26 |
# File 'lib/sequel/lib/sequel/plugins/caching.rb', line 21 def self.configure(model, store, opts={}) model.instance_eval do @cache_store = store @cache_ttl = opts[:ttl] || 3600 end end |