Class: AsyncStorage::Repo
- Inherits:
-
Object
- Object
- AsyncStorage::Repo
- Defined in:
- lib/async_storage/repo.rb
Instance Attribute Summary collapse
-
#resolver_class ⇒ Object
readonly
Returns the value of attribute resolver_class.
Class Method Summary collapse
-
.ack(klass:, args:, **options) ⇒ Hash, NilClass
Store a fresh content into redis.
Instance Method Summary collapse
-
#alloc(*args) ⇒ Object
Build an Allocator instance.
-
#exist?(*args) ⇒ Boolean
Check if a fresh value exist.
- #expires_in ⇒ Object
-
#fresh?(*args) ⇒ Boolean
Check if a fresh object exists into the storage.
-
#get(*args) ⇒ Object, NilClass
Async get value with a given key.
-
#get!(*args) ⇒ Object
Sync get value with a given value.
-
#initialize(resolver_class, **options) ⇒ Repo
constructor
A new instance of Repo.
-
#invalidate(*args) ⇒ Boolean
Expire object the object with a given key.
-
#invalidate!(*args) ⇒ Boolean
Delete object with a given key.
- #namespace ⇒ Object
-
#refresh(*args) ⇒ Object, NilClass
Invalidate object with the given key and update content according to the strategy.
-
#refresh!(*args) ⇒ Object
Fetch data from resolver and store it into redis.
-
#stale?(*args) ⇒ NilClass, Boolean
Check if object with a given key is stale.
Constructor Details
#initialize(resolver_class, **options) ⇒ Repo
Returns a new instance of Repo.
13 14 15 16 17 |
# File 'lib/async_storage/repo.rb', line 13 def initialize(resolver_class, **) validate_resolver_class!(resolver_class) @resolver_class = resolver_class @options = end |
Instance Attribute Details
#resolver_class ⇒ Object (readonly)
Returns the value of attribute resolver_class.
7 8 9 |
# File 'lib/async_storage/repo.rb', line 7 def resolver_class @resolver_class end |
Class Method Details
.ack(klass:, args:, **options) ⇒ Hash, NilClass
Store a fresh content into redis. This method is invoked by a background job.
25 26 27 |
# File 'lib/async_storage/repo.rb', line 25 def self.ack(klass:, args:, **) new(klass, **).refresh!(*args) end |
Instance Method Details
#alloc(*args) ⇒ Object
Build an Allocator instance
95 96 97 |
# File 'lib/async_storage/repo.rb', line 95 def alloc(*args) Allocator.new(self, *args) end |
#exist?(*args) ⇒ Boolean
Check if a fresh value exist.
74 75 76 |
# File 'lib/async_storage/repo.rb', line 74 def exist?(*args) alloc(*args).exist? end |
#expires_in ⇒ Object
99 100 101 |
# File 'lib/async_storage/repo.rb', line 99 def expires_in @options[:expires_in] || AsyncStorage.config.expires_in end |
#fresh?(*args) ⇒ Boolean
Check if a fresh object exists into the storage
88 89 90 |
# File 'lib/async_storage/repo.rb', line 88 def fresh?(*args) alloc(*args).fresh? end |
#get(*args) ⇒ Object, NilClass
Async get value with a given key
32 33 34 |
# File 'lib/async_storage/repo.rb', line 32 def get(*args) alloc(*args).get end |
#get!(*args) ⇒ Object
Sync get value with a given value
39 40 41 |
# File 'lib/async_storage/repo.rb', line 39 def get!(*args) alloc(*args).get! end |
#invalidate(*args) ⇒ Boolean
Expire object the object with a given key. The stale object will not be removed
46 47 48 |
# File 'lib/async_storage/repo.rb', line 46 def invalidate(*args) alloc(*args).invalidate end |
#invalidate!(*args) ⇒ Boolean
Delete object with a given key.
53 54 55 |
# File 'lib/async_storage/repo.rb', line 53 def invalidate!(*args) alloc(*args).invalidate! end |
#namespace ⇒ Object
103 104 105 |
# File 'lib/async_storage/repo.rb', line 103 def namespace @options[:namespace] end |
#refresh(*args) ⇒ Object, NilClass
Invalidate object with the given key and update content according to the strategy
60 61 62 |
# File 'lib/async_storage/repo.rb', line 60 def refresh(*args) alloc(*args).refresh end |
#refresh!(*args) ⇒ Object
Fetch data from resolver and store it into redis
67 68 69 |
# File 'lib/async_storage/repo.rb', line 67 def refresh!(*args) alloc(*args).refresh! end |
#stale?(*args) ⇒ NilClass, Boolean
Check if object with a given key is stale
81 82 83 |
# File 'lib/async_storage/repo.rb', line 81 def stale?(*args) alloc(*args).stale? end |