Class: SgPostcode::CacheAdapter
- Inherits:
-
Object
- Object
- SgPostcode::CacheAdapter
- Defined in:
- lib/sg_postcode/services/cache_adapter.rb
Constant Summary collapse
- @@hash_name =
"SgPostcodeCaching"
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(key) ⇒ CacheAdapter
constructor
A new instance of CacheAdapter.
- #store(key, value) ⇒ Object
- #value_of(key) ⇒ Object
Constructor Details
#initialize(key) ⇒ CacheAdapter
Returns a new instance of CacheAdapter.
5 6 7 8 |
# File 'lib/sg_postcode/services/cache_adapter.rb', line 5 def initialize(key) @cache = Redis.new @key = key end |
Class Method Details
.hash_name=(hash_name) ⇒ Object
10 11 12 |
# File 'lib/sg_postcode/services/cache_adapter.rb', line 10 def self.hash_name=(hash_name) @@hash_name = hash_name end |
Instance Method Details
#fetch ⇒ Object
14 15 16 |
# File 'lib/sg_postcode/services/cache_adapter.rb', line 14 def fetch value_of @key end |
#store(key, value) ⇒ Object
18 19 20 21 |
# File 'lib/sg_postcode/services/cache_adapter.rb', line 18 def store(key, value) @cache.hset(@@hash_name, key, value) value end |
#value_of(key) ⇒ Object
23 24 25 |
# File 'lib/sg_postcode/services/cache_adapter.rb', line 23 def value_of(key) @cache.hget(@@hash_name, key) end |