Class: CacheMethod::Generation
- Inherits:
-
Object
- Object
- CacheMethod::Generation
- Defined in:
- lib/cache_method/generation.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(obj, method_id) ⇒ Generation
constructor
A new instance of Generation.
- #mark_passing ⇒ Object
- #method_signature ⇒ Object
- #obj_digest ⇒ Object
Constructor Details
#initialize(obj, method_id) ⇒ Generation
Returns a new instance of Generation.
10 11 12 13 |
# File 'lib/cache_method/generation.rb', line 10 def initialize(obj, method_id) @obj = obj @method_id = method_id end |
Instance Attribute Details
#method_id ⇒ Object (readonly)
Returns the value of attribute method_id.
16 17 18 |
# File 'lib/cache_method/generation.rb', line 16 def method_id @method_id end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
15 16 17 |
# File 'lib/cache_method/generation.rb', line 15 def obj @obj end |
Class Method Details
.random_name ⇒ Object
5 6 7 |
# File 'lib/cache_method/generation.rb', line 5 def random_name rand(100_000_000).to_s end |
Instance Method Details
#cache_key ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/cache_method/generation.rb', line 26 def cache_key if obj.is_a?(::Class) or obj.is_a?(::Module) [ 'CacheMethod', 'Generation', method_signature ].join ',' else [ 'CacheMethod', 'Generation', method_signature, obj_digest ].join ',' end end |
#current ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cache_method/generation.rb', line 34 def current if cached_v = Config.instance.storage.get(cache_key) cached_v else v = Generation.random_name # never expire! Config.instance.storage.set cache_key, v, 0 v end end |
#mark_passing ⇒ Object
45 46 47 |
# File 'lib/cache_method/generation.rb', line 45 def mark_passing Config.instance.storage.delete cache_key end |
#method_signature ⇒ Object
18 19 20 |
# File 'lib/cache_method/generation.rb', line 18 def method_signature @method_signature ||= ::CacheMethod.method_signature(obj, method_id) end |
#obj_digest ⇒ Object
22 23 24 |
# File 'lib/cache_method/generation.rb', line 22 def obj_digest @obj_digest ||= ::Digest::SHA1.hexdigest(::Marshal.dump(obj.respond_to?(:as_cache_key) ? obj.as_cache_key : obj)) end |