module InfoparkComponentCache::DelayedGuard

@author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>

This module provides an easy way to create delayed guards by using meta programming.

@example Delaying an ObjectCount which guards on :object_count

class DelayedObjectCount < ObjectCount
  include DelayedGuard
  delay :object_count, for: 10.minutes
end

@note Including classes must implement options method which

completely described the object state and returns a hash.

Public Class Methods

included(base) click to toggle source
# File lib/infopark_component_cache/delayed_guard.rb, line 19
def self.included(base)
  base.send(:extend, ClassMethods)
end

Protected Instance Methods

delay_value(method_name, value, expiration) click to toggle source
# File lib/infopark_component_cache/delayed_guard.rb, line 35
def delay_value(method_name, value, expiration)
  volatile_cache.write(delayed_value_key(method_name), value, expires_in: expiration)
  value
end
delayed_value(method_name) click to toggle source
# File lib/infopark_component_cache/delayed_guard.rb, line 27
def delayed_value(method_name)
  volatile_cache.read(delayed_value_key(method_name))
end
delayed_value_key(method_name) click to toggle source
# File lib/infopark_component_cache/delayed_guard.rb, line 40
def delayed_value_key(method_name)
  KeyGenerator.generate_key(options.merge({
                                            delayed_method_name: method_name,
                                            delayed_class_name: self.class.name
                                          }))
end
still_delayed?(method_name) click to toggle source
# File lib/infopark_component_cache/delayed_guard.rb, line 31
def still_delayed?(method_name)
  volatile_cache.exist?(delayed_value_key(method_name))
end