Module: Joggle::Store::PStore::Cache
- Included in:
- All
- Defined in:
- lib/joggle/store/pstore/cache.rb
Overview
Mixin that implements cache store methods for PStore backend.
Note: You’re probably looking for Joggle::Store::PStore::All
Instance Method Summary collapse
-
#add_cached(key, row) ⇒ Object
Add cache entry.
-
#cache_store_key(key) ⇒ Object
Map the given key to a pstore root key.
-
#delete_cached(key) ⇒ Object
Delete the given entry.
-
#get_cached(key) ⇒ Object
Get cache entry.
-
#has_cached?(key) ⇒ Boolean
Does the given entry exist?.
Instance Method Details
#add_cached(key, row) ⇒ Object
Add cache entry.
15 16 17 18 19 20 21 |
# File 'lib/joggle/store/pstore/cache.rb', line 15 def add_cached(key, row) key = cache_store_key(key) @store.transaction do |s| s[key] = {}.merge(row) end end |
#cache_store_key(key) ⇒ Object
Map the given key to a pstore root key.
59 60 61 |
# File 'lib/joggle/store/pstore/cache.rb', line 59 def cache_store_key(key) 'cache-' << Digest::MD5.hexdigest(key) end |
#delete_cached(key) ⇒ Object
Delete the given entry.
48 49 50 51 52 53 54 |
# File 'lib/joggle/store/pstore/cache.rb', line 48 def delete_cached(key) key = cache_store_key(key) @store.transaction do |s| s.delete(key) end end |
#get_cached(key) ⇒ Object
Get cache entry.
26 27 28 29 30 31 32 |
# File 'lib/joggle/store/pstore/cache.rb', line 26 def get_cached(key) key = cache_store_key(key) @store.transaction(true) do |s| s[key] end end |
#has_cached?(key) ⇒ Boolean
Does the given entry exist?
37 38 39 40 41 42 43 |
# File 'lib/joggle/store/pstore/cache.rb', line 37 def has_cached?(key) key = cache_store_key(key) @store.transaction(true) do |s| s.root?(key) end end |