Class: MacawFramework::Cache
- Inherits:
-
Object
- Object
- MacawFramework::Cache
- Includes:
- Singleton
- Defined in:
- lib/macaw_framework/cache.rb
Overview
This singleton class allows to manually cache parameters and other data.
Instance Attribute Summary collapse
-
#invalidation_frequency ⇒ Object
Returns the value of attribute invalidation_frequency.
Class Method Summary collapse
-
.read(tag) ⇒ String|nil
Read the value with the specified tag.
-
.write(tag, value, expires_in: 3600) ⇒ Object
Write a value to Cache memory.
Instance Method Summary collapse
-
#read(tag) ⇒ String|nil
Read the value with the specified tag.
-
#write(tag, value, expires_in: 3600) ⇒ Object
Write a value to Cache memory.
Instance Attribute Details
#invalidation_frequency ⇒ Object
Returns the value of attribute invalidation_frequency.
13 14 15 |
# File 'lib/macaw_framework/cache.rb', line 13 def invalidation_frequency @invalidation_frequency end |
Class Method Details
.read(tag) ⇒ String|nil
Read the value with the specified tag. Can be called statically or from an instance.
53 |
# File 'lib/macaw_framework/cache.rb', line 53 def self.read(tag) = MacawFramework::Cache.instance.read(tag) |
.write(tag, value, expires_in: 3600) ⇒ Object
Write a value to Cache memory. Can be called statically or from an instance.
25 26 27 |
# File 'lib/macaw_framework/cache.rb', line 25 def self.write(tag, value, expires_in: 3600) MacawFramework::Cache.instance.write(tag, value, expires_in: expires_in) end |
Instance Method Details
#read(tag) ⇒ String|nil
Read the value with the specified tag. Can be called statically or from an instance.
63 64 65 |
# File 'lib/macaw_framework/cache.rb', line 63 def read(tag) @mutex.synchronize { @cache.dig(tag, :value) } end |
#write(tag, value, expires_in: 3600) ⇒ Object
Write a value to Cache memory. Can be called statically or from an instance.
39 40 41 42 43 |
# File 'lib/macaw_framework/cache.rb', line 39 def write(tag, value, expires_in: 3600) @mutex.synchronize do @cache.store(tag, { value: value, expires_in: Time.now + expires_in }) end end |