Module: Aerogel::Cache
- Defined in:
- lib/aerogel/core/cache.rb
Class Method Summary collapse
-
.cache ⇒ Object
Returns cache structure.
-
.cache_key(args) ⇒ Object
Calculates a cache key for a single object, or a compound cache key for a list of objects.
-
.cacheable(*args, &block) ⇒ Object
Retrieves cache entry by calculated cache key of
args
, or runs givenblock
, stores its result in the cache and returns its value. -
.clear! ⇒ Object
Clears cache completely.
-
.keys ⇒ Object
Returns list of stored keys.
Class Method Details
.cache ⇒ Object
Returns cache structure.
32 33 34 |
# File 'lib/aerogel/core/cache.rb', line 32 def self.cache @cache ||= initialize_cache end |
.cache_key(args) ⇒ Object
Calculates a cache key for a single object, or a compound cache key for a list of objects.
12 13 14 15 16 17 18 |
# File 'lib/aerogel/core/cache.rb', line 12 def self.cache_key( args ) if Array === args args.flatten.map{|o| object_to_cache_key o }.join("/") else object_to_cache_key args end end |
.cacheable(*args, &block) ⇒ Object
Retrieves cache entry by calculated cache key of args
, or runs given block
, stores its result in the cache and returns its value.
23 24 25 26 27 28 |
# File 'lib/aerogel/core/cache.rb', line 23 def self.cacheable( *args, &block ) key = cache_key args cache.getset key do yield key end end |
.clear! ⇒ Object
Clears cache completely.
44 45 46 |
# File 'lib/aerogel/core/cache.rb', line 44 def self.clear! @cache.clear end |
.keys ⇒ Object
Returns list of stored keys.
38 39 40 |
# File 'lib/aerogel/core/cache.rb', line 38 def self.keys cache.to_a.map(&:first) end |