Class: Platform::Cache
Class Method Summary collapse
- .cache ⇒ Object
- .decrement(key, amount = 1) ⇒ Object
- .delete(key, options = nil) ⇒ Object
- .enabled? ⇒ Boolean
- .fetch(key, options = {}) ⇒ Object
- .get(key, options = {}) ⇒ Object
- .increment(key, amount = 1) ⇒ Object
- .set(key, value, options = {}) ⇒ Object
- .versioned_key(key) ⇒ Object
Class Method Details
.cache ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/platform/cache.rb', line 26 def self.cache @cache ||= begin if Platform::Config.cache_adapter == 'ActiveSupport::Cache' store_params = [Platform::Config.cache_store].flatten store_params[0] = store_params[0].to_sym ActiveSupport::Cache.lookup_store(*store_params) else eval(Platform::Config.cache_adapter) end end end |
.decrement(key, amount = 1) ⇒ Object
63 64 65 66 |
# File 'lib/platform/cache.rb', line 63 def self.decrement(key, amount = 1) return unless enabled? cache.decrement(versioned_key(key), amount) end |
.delete(key, options = nil) ⇒ Object
53 54 55 56 |
# File 'lib/platform/cache.rb', line 53 def self.delete(key, = nil) return unless enabled? cache.delete(versioned_key(key), ) end |
.enabled? ⇒ Boolean
38 39 40 |
# File 'lib/platform/cache.rb', line 38 def self.enabled? Platform::Config.enable_caching? end |
.fetch(key, options = {}) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/platform/cache.rb', line 46 def self.fetch(key, = {}) return yield unless enabled? cache.fetch(versioned_key(key), ) do yield end end |
.get(key, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/platform/cache.rb', line 73 def self.get(key, = {}) return unless enabled? cache.get(key, ) end |
.increment(key, amount = 1) ⇒ Object
58 59 60 61 |
# File 'lib/platform/cache.rb', line 58 def self.increment(key, amount = 1) return unless enabled? cache.increment(versioned_key(key), amount) end |
.set(key, value, options = {}) ⇒ Object
68 69 70 71 |
# File 'lib/platform/cache.rb', line 68 def self.set(key, value, = {}) return unless enabled? cache.set(key, value, ) end |
.versioned_key(key) ⇒ Object
42 43 44 |
# File 'lib/platform/cache.rb', line 42 def self.versioned_key(key) "#{Platform::Config.cache_version}_#{key}" end |