Class: CacheMethod::Config

Inherits:
Object
  • Object
show all
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

Instance Method Details

#default_ttlObject

:nodoc:



44
45
46
# File 'lib/cache_method/config.rb', line 44

def default_ttl #:nodoc:
  @default_ttl || 60
end

#default_ttl=(seconds) ⇒ Object

TTL for method caches. Defaults to 60 seconds.

Example:

CacheMethod.config.default_ttl = 120 # seconds


40
41
42
# File 'lib/cache_method/config.rb', line 40

def default_ttl=(seconds)
  @default_ttl = seconds
end

#storageObject

:nodoc:



32
33
34
# File 'lib/cache_method/config.rb', line 32

def storage #:nodoc:
  @storage || raise("You need to set CacheMethod.config.storage with a cache storage of your choice")
end

#storage=(raw_client) ⇒ 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'


28
29
30
# File 'lib/cache_method/config.rb', line 28

def storage=(raw_client)
  @storage = ::Cache.new raw_client
end