Class: CacheMethod::Config
- Inherits:
-
Object
- Object
- CacheMethod::Config
- Includes:
- Singleton
- Defined in:
- lib/cache_method/config.rb
Overview
Here’s where you set config options.
Example:
CacheMethod.config.storage = Memcached.new '127.0.0.1:11211'
CacheMethod.config.default_ttl = 120 # seconds
You’d probably put this in your Rails config/initializers, for example.
Instance Method Summary collapse
-
#default_ttl ⇒ Object
:nodoc:.
-
#default_ttl=(seconds) ⇒ Object
TTL for method caches.
-
#generational=(boolean) ⇒ Object
Whether to use “generational” caching.
-
#generational? ⇒ Boolean
:nodoc:.
-
#storage ⇒ Object
:nodoc:.
-
#storage=(storage = nil) ⇒ Object
Storage for the cache.
Instance Method Details
#default_ttl ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/cache_method/config.rb', line 58 def default_ttl #:nodoc: @default_ttl || 86_400 end |
#default_ttl=(seconds) ⇒ Object
TTL for method caches. Defaults to 24 hours or 86,400 seconds.
Example:
CacheMethod.config.default_ttl = 120 # seconds
54 55 56 |
# File 'lib/cache_method/config.rb', line 54 def default_ttl=(seconds) @default_ttl = seconds end |
#generational=(boolean) ⇒ Object
Whether to use “generational” caching. Default is true.
Pro: enables clearing/flushing/expiring specific methods Con: requires an extra trip to memcached to get the current “generation”
Set to false if you just flush everything and don’t need to selectively flush particular methods
20 21 22 |
# File 'lib/cache_method/config.rb', line 20 def generational=(boolean) @generational = boolean end |
#generational? ⇒ Boolean
:nodoc:
24 25 26 |
# File 'lib/cache_method/config.rb', line 24 def generational? #:nodoc: @generational == true or @generational.nil? end |
#storage ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/cache_method/config.rb', line 46 def storage #:nodoc: @storage ||= ::Cache.new end |
#storage=(storage = nil) ⇒ Object
Storage for the cache.
Supported memcached clients:
-
memcached (either a Memcached or a Memcached::Rails)
-
dalli (either a Dalli::Client or an ActiveSupport::Cache::DalliStore)
-
memcache-client (MemCache, the one commonly used by Rails)
Supported Redis clients:
Uses the cache gem to wrap these, so support depends on that gem
Example:
CacheMethod.config.storage = Memcached.new '127.0.0.1:11211'
42 43 44 |
# File 'lib/cache_method/config.rb', line 42 def storage=(storage = nil) @storage = ::Cache.wrap storage end |