Class: CacheMethod::Config
- Inherits:
-
Object
- Object
- CacheMethod::Config
- 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_generational_ttl ⇒ Object
:nodoc:.
-
#default_generational_ttl=(seconds) ⇒ Object
TTL for method generational caches.
-
#default_ttl ⇒ Object
:nodoc:.
-
#default_ttl=(seconds) ⇒ Object
TTL for method caches.
-
#generational=(boolean) ⇒ Object
Whether to use “generational” caching.
-
#generational? ⇒ Boolean
:nodoc:.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#storage ⇒ Object
:nodoc:.
-
#storage=(storage = nil) ⇒ Object
Storage for the cache.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 |
# File 'lib/cache_method/config.rb', line 13 def initialize @mutex = ::Mutex.new end |
Instance Method Details
#default_generational_ttl ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/cache_method/config.rb', line 75 def default_generational_ttl #:nodoc: @default_generational_ttl || 0 end |
#default_generational_ttl=(seconds) ⇒ Object
TTL for method generational caches. Defaults to 0 (never).
Example:
CacheMethod.config.default_generational_ttl = 120 # seconds
71 72 73 |
# File 'lib/cache_method/config.rb', line 71 def default_generational_ttl=(seconds) @default_generational_ttl = seconds end |
#default_ttl ⇒ Object
:nodoc:
63 64 65 |
# File 'lib/cache_method/config.rb', line 63 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
59 60 61 |
# File 'lib/cache_method/config.rb', line 59 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
23 24 25 |
# File 'lib/cache_method/config.rb', line 23 def generational=(boolean) @generational = boolean end |
#generational? ⇒ Boolean
:nodoc:
27 28 29 |
# File 'lib/cache_method/config.rb', line 27 def generational? #:nodoc: @generational == true or @generational.nil? end |
#storage ⇒ Object
:nodoc:
49 50 51 52 53 |
# File 'lib/cache_method/config.rb', line 49 def storage #:nodoc: @storage || @mutex.synchronize do @storage ||= ::Cache.new end 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'
45 46 47 |
# File 'lib/cache_method/config.rb', line 45 def storage=(storage = nil) @storage = ::Cache.wrap storage end |