The main DB class. This is the public API for the library.
Works the same as get, but will fire the action defined for the given key after the timeout defined for that key has elapsed.
Returns nil for a key which has not had any action defined for it yet.
# File lib/volatiledb.rb, line 55 def fetch(key) checking key do |k| item = @db[k] delta = now - item[:last_access] delta > item[:timeout] ? sync(k) : get(k) end end
Read the data for the given key from storage. If the underlying storage has disappeared, it will be re-initialized by calling the action defined for that key again. After the storage has been re-initialized, its value will be read and returned.
Returns nil for a key which has not had any action defined for it yet.
# File lib/volatiledb.rb, line 40 def get(key) data = raw_get key if data.nil? sync key else data end end
Works the same as fetch, but ignores timeout and calls the defined action every time. Should be used sparingly as it re-initializes storage on every call.
Returns nil for a key which has not had any action defined for it yet.
# File lib/volatiledb.rb, line 70 def pull(key) sync key end
Define an action for a given key. The action should return a String. A timeout in seconds may optionally be defined. Default is 3 seconds.
# File lib/volatiledb.rb, line 26 def put(key, timeout=3, &action) populate_db key, timeout, action raw_put key key end
Generated with the Darkfish Rdoc Generator 2.