Module: AsyncCache::Workers::Base
- Included in:
- ActiveJobWorker, SidekiqWorker
- Defined in:
- lib/async_cache/workers/base.rb
Class Method Summary collapse
- .enqueue_async_job(key:, version:, expires_in:, block:, arguments:) ⇒ Object
-
.has_workers? ⇒ Boolean
Abstract public interface to workers that process AsyncCache jobs.
Instance Method Summary collapse
-
#perform(key, version, expires_in, block_arguments, block_source) ⇒ Object
key - String or array cache key computed by ‘AsyncCache` version - Monotonically increasing integer indicating the version of the resource being cached expires_in - Optional expiration to pass to the cache store block_arguments - Arguments with which to call the block block_source - Ruby source to evaluate to produce the value.
Class Method Details
.enqueue_async_job(key:, version:, expires_in:, block:, arguments:) ⇒ Object
22 23 24 |
# File 'lib/async_cache/workers/base.rb', line 22 def self.enqueue_async_job(key:, version:, expires_in:, block:, arguments:) raise NotImplementedError end |
.has_workers? ⇒ Boolean
Abstract public interface to workers that process AsyncCache jobs
18 19 20 |
# File 'lib/async_cache/workers/base.rb', line 18 def self.has_workers? raise NotImplementedError end |
Instance Method Details
#perform(key, version, expires_in, block_arguments, block_source) ⇒ Object
key - String or array cache key computed by ‘AsyncCache` version - Monotonically increasing integer indicating the version
of the resource being cached
expires_in - Optional expiration to pass to the cache store block_arguments - Arguments with which to call the block block_source - Ruby source to evaluate to produce the value
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/async_cache/workers/base.rb', line 32 def perform key, version, expires_in, block_arguments, block_source t0 = Time.now _cached_data, cached_version = backend.read key return unless version > (cached_version || 0) value = [eval(block_source).call(*block_arguments), version] backend.write key, value, :expires_in => expires_in end |