| Module | MCollective::Cache |
| In: |
lib/mcollective/cache.rb
|
A class to manage a number of named caches. Each cache can have a unique timeout for keys in it and each cache has an independent Mutex protecting access to it.
This cache is setup early in the process of loading the mcollective libraries, before any threads are created etc making it suitable as a cross thread cache or just a store for Mutexes you need to use across threads like in an Agent or something.
# sets up a new cache, noop if it already exist
Cache.setup(:ddl, 600)
=> true
# writes an item to the :ddl cache, this item will
# be valid on the cache for 600 seconds
Cache.write(:ddl, :something, "value")
=> "value"
# reads from the cache, read failures due to non existing
# data or expired data will raise an exception
Cache.read(:ddl, :something)
=> "value"
# time left till expiry, raises if nothing is found
Cache.ttl(:ddl, :something)
=> 500
# forcibly evict something from the cache
Cache.invalidate!(:ddl, :something)
=> "value"
# deletes an entire named cache and its mutexes
Cache.delete!(:ddl)
=> true
# you can also just use this cache as a global mutex store
Cache.setup(:mylock)
Cache.synchronize(:mylock) do
do_something()
end