Class: AwsDevUtils::Cache
- Inherits:
-
Object
- Object
- AwsDevUtils::Cache
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/aws-dev-utils/cache.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
writeonly
for testing.
Instance Method Summary collapse
Instance Attribute Details
#backend=(value) ⇒ Object
for testing
9 10 11 |
# File 'lib/aws-dev-utils/cache.rb', line 9 def backend=(value) @backend = value end |
Instance Method Details
#fetch(key, exp = 60, &block) ⇒ Object
16 17 18 |
# File 'lib/aws-dev-utils/cache.rb', line 16 def fetch key, exp=60, &block get(key) or block.().tap {|x| set(key, x, exp)} end |
#get(key) ⇒ Object
20 21 22 |
# File 'lib/aws-dev-utils/cache.rb', line 20 def get key deserialize backend.get key.to_s rescue nil end |
#set(key, value, expiration) ⇒ Object
24 25 26 |
# File 'lib/aws-dev-utils/cache.rb', line 24 def set key, value, expiration backend.set key.to_s, serialize(value), expiration rescue nil end |