Module: Sprockets::Caching
- Included in:
- Base
- Defined in:
- lib/sprockets/caching.rb
Overview
‘Caching` is an internal mixin whose public methods are exposed on the `Environment` and `Index` classes.
Instance Method Summary collapse
-
#cache_get(key) ⇒ Object
Low level cache getter for ‘key`.
-
#cache_set(key, value) ⇒ Object
Low level cache setter for ‘key`.
Instance Method Details
#cache_get(key) ⇒ Object
Low level cache getter for ‘key`. Checks a number of supported cache interfaces.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sprockets/caching.rb', line 7 def cache_get(key) # `Cache#get(key)` for Memcache if cache.respond_to?(:get) cache.get(key) # `Cache#[key]` so `Hash` can be used elsif cache.respond_to?(:[]) cache[key] # `Cache#read(key)` for `ActiveSupport::Cache` support elsif cache.respond_to?(:read) cache.read(key) else nil end end |
#cache_set(key, value) ⇒ Object
Low level cache setter for ‘key`. Checks a number of supported cache interfaces.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sprockets/caching.rb', line 27 def cache_set(key, value) # `Cache#set(key, value)` for Memcache if cache.respond_to?(:set) cache.set(key, value) # `Cache#[key]=value` so `Hash` can be used elsif cache.respond_to?(:[]=) cache[key] = value # `Cache#write(key, value)` for `ActiveSupport::Cache` support elsif cache.respond_to?(:write) cache.write(key, value) end value end |