Class: LockMethod::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/lock_method/config.rb

Overview

Here’s where you set config options.

Example:

LockMethod.config.storage = Memcached.new '127.0.0.1:11211'

You’d probably put this in your Rails config/initializers, for example.

Instance Method Summary collapse

Instance Method Details

#default_ttlObject

:nodoc:



50
51
52
# File 'lib/lock_method/config.rb', line 50

def default_ttl #:nodoc:
  @default_ttl || 86_400
end

#default_ttl=(seconds) ⇒ Object

TTL for method caches. Defaults to 24 hours.

Example:

LockMethod.config.default_ttl = 120 # seconds


46
47
48
# File 'lib/lock_method/config.rb', line 46

def default_ttl=(seconds)
  @default_ttl = seconds
end

#storageObject

:nodoc:



38
39
40
# File 'lib/lock_method/config.rb', line 38

def storage #:nodoc:
  @storage ||= DefaultStorageClient.instance
end

#storage=(storage = nil) ⇒ Object

Storage for keeping lockfiles.

Defaults to using the filesystem’s temp dir.

Supported memcached clients:

  • memcached (either a Memcached or a Memcached::Rails)

  • dalli (either a Dalli::Client or an ActiveSupport::Cache::DalliStore)

  • memcache-storage (MemCache, the one commonly used by Rails)

Supported Redis clients:

Supports anything that works with the cache gem.

Example:

LockMethod.config.storage = Memcached.new '127.0.0.1:11211'


29
30
31
32
33
34
35
36
# File 'lib/lock_method/config.rb', line 29

def storage=(storage = nil)
  if storage.nil?
    # set this to nil so that the DefaultStorageClient can take over.
    @storage = nil
  else
    @storage = ::Cache.wrap storage
  end
end