Class: CacheMethod::Generation

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_method/generation.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, method_id) ⇒ Generation

Returns a new instance of Generation.



3
4
5
6
7
8
# File 'lib/cache_method/generation.rb', line 3

def initialize(obj, method_id)
  @obj = obj
  @method_id = method_id
  @method_signature = CacheMethod.method_signature obj, method_id
  @fetch_mutex = ::Mutex.new
end

Instance Attribute Details

#method_idObject (readonly)

Returns the value of attribute method_id.



11
12
13
# File 'lib/cache_method/generation.rb', line 11

def method_id
  @method_id
end

#method_signatureObject (readonly)

Returns the value of attribute method_signature.



12
13
14
# File 'lib/cache_method/generation.rb', line 12

def method_signature
  @method_signature
end

#objObject (readonly)

Returns the value of attribute obj.



10
11
12
# File 'lib/cache_method/generation.rb', line 10

def obj
  @obj
end

Instance Method Details

#fetchObject



14
15
16
17
18
19
20
21
22
# File 'lib/cache_method/generation.rb', line 14

def fetch
  if existing = get
    existing
  else
    @fetch_mutex.synchronize do
      get || set
    end
  end
end

#mark_passingObject



24
25
26
# File 'lib/cache_method/generation.rb', line 24

def mark_passing
  CacheMethod.config.storage.delete cache_key
end