Module: AsyncCache::Workers::Base

Included in:
ActiveJobWorker, SidekiqWorker
Defined in:
lib/async_cache/workers/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject

Clear the active jobs from this worker's queue.

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/async_cache/workers/base.rb', line 27

def self.clear
  raise NotImplementedError
end

.enqueue_async_job(key:, version:, expires_in:, block:, arguments:) ⇒ Object

Public interface for enqueuing jobs. This is what is called by Store.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/async_cache/workers/base.rb', line 33

def self.enqueue_async_job(key:, version:, expires_in:, block:, arguments:)
  raise NotImplementedError
end

.has_workers?Boolean

Returns whether or not workers are running to process enqueue AsyncCache jobs. Return false if this functionality isn't available by the underlying system.

Returns:

  • (Boolean)

    Returns whether or not workers are running to process enqueue AsyncCache jobs. Return false if this functionality isn't available by the underlying system.

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/async_cache/workers/base.rb', line 22

def self.has_workers?
  raise NotImplementedError
end

Instance Method Details

#backendObject (private)



56
57
58
# File 'lib/async_cache/workers/base.rb', line 56

def backend
  AsyncCache.backend
end

#perform(key, version, expires_in, block_arguments, block_source) ⇒ Object

Parameters:

  • key (String)

    String or array cache key computed by AsyncCache

  • version (Fixnum)

    Monotonically increasing integer indicating the version of the resource being cached

  • expires_in (Fixnum)

    Optional expiration to pass to the cache store

  • block_arguments (Array)

    Arguments with which to call the block

  • block_source (String)

    Ruby source to evaluate to produce the value



43
44
45
46
47
48
49
50
51
52
# File 'lib/async_cache/workers/base.rb', line 43

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