Class: LockMethod::Config
- Inherits:
-
Object
- Object
- LockMethod::Config
- 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
-
#default_ttl ⇒ Object
:nodoc:.
-
#default_ttl=(seconds) ⇒ Object
TTL for method caches.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#storage ⇒ Object
:nodoc:.
-
#storage=(storage = nil) ⇒ Object
Storage for keeping lockfiles.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
11 12 13 |
# File 'lib/lock_method/config.rb', line 11 def initialize @mutex = ::Mutex.new end |
Instance Method Details
#default_ttl ⇒ Object
:nodoc:
54 55 56 |
# File 'lib/lock_method/config.rb', line 54 def default_ttl #:nodoc: @default_ttl || 86_400 end |
#default_ttl=(seconds) ⇒ Object
50 51 52 |
# File 'lib/lock_method/config.rb', line 50 def default_ttl=(seconds) @default_ttl = seconds end |
#storage ⇒ Object
:nodoc:
40 41 42 43 44 |
# File 'lib/lock_method/config.rb', line 40 def storage #:nodoc: @storage || @mutex.synchronize do @storage ||= DefaultStorageClient.new end 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'
31 32 33 34 35 36 37 38 |
# File 'lib/lock_method/config.rb', line 31 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 |