Class: CacheMethod::Epoch
- Inherits:
-
Object
- Object
- CacheMethod::Epoch
- Defined in:
- lib/cache_method/epoch.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#method_id ⇒ Object
readonly
Returns the value of attribute method_id.
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #current ⇒ Object
-
#initialize(options = {}) ⇒ Epoch
constructor
A new instance of Epoch.
- #mark_passing ⇒ Object
- #method_signature ⇒ Object
- #obj_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Epoch
Returns a new instance of Epoch.
19 20 21 22 23 |
# File 'lib/cache_method/epoch.rb', line 19 def initialize( = {}) .each do |k, v| instance_variable_set "@#{k}", v end end |
Instance Attribute Details
#method_id ⇒ Object (readonly)
Returns the value of attribute method_id.
26 27 28 |
# File 'lib/cache_method/epoch.rb', line 26 def method_id @method_id end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
25 26 27 |
# File 'lib/cache_method/epoch.rb', line 25 def obj @obj end |
Class Method Details
.current(options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/cache_method/epoch.rb', line 4 def current( = {}) epoch = new epoch.current end |
.mark_passing(options = {}) ⇒ Object
9 10 11 12 |
# File 'lib/cache_method/epoch.rb', line 9 def mark_passing( = {}) epoch = new epoch.mark_passing end |
.random_name ⇒ Object
14 15 16 |
# File 'lib/cache_method/epoch.rb', line 14 def random_name rand(1_000_000).to_s end |
Instance Method Details
#cache_key ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/cache_method/epoch.rb', line 36 def cache_key if obj.is_a? ::Class [ 'CacheMethod', 'Epoch', method_signature ].join ',' else [ 'CacheMethod', 'Epoch', method_signature, obj_hash ].join ',' end end |
#current ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cache_method/epoch.rb', line 44 def current if cached_v = Config.instance.storage.get(cache_key) cached_v else v = Epoch.random_name # never expire! Config.instance.storage.set cache_key, v, 0 v end end |
#mark_passing ⇒ Object
55 56 57 |
# File 'lib/cache_method/epoch.rb', line 55 def mark_passing Config.instance.storage.delete cache_key end |
#method_signature ⇒ Object
28 29 30 |
# File 'lib/cache_method/epoch.rb', line 28 def method_signature @method_signature ||= ::CacheMethod.method_signature(obj, method_id) end |
#obj_hash ⇒ Object
32 33 34 |
# File 'lib/cache_method/epoch.rb', line 32 def obj_hash @obj_hash ||= obj.hash end |