Class: VSM::Meta::SnapshotCache

Inherits:
Object
  • Object
show all
Defined in:
lib/vsm/meta/snapshot_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ SnapshotCache

Returns a new instance of SnapshotCache.



8
9
10
11
12
# File 'lib/vsm/meta/snapshot_cache.rb', line 8

def initialize(builder)
  @builder = builder
  @mutex = Mutex.new
  @snapshot = nil
end

Instance Method Details

#fetchObject



14
15
16
17
18
# File 'lib/vsm/meta/snapshot_cache.rb', line 14

def fetch
  @mutex.synchronize do
    @snapshot ||= { generated_at: Time.now.utc, data: @builder.call }
  end
end

#invalidate!Object



20
21
22
# File 'lib/vsm/meta/snapshot_cache.rb', line 20

def invalidate!
  @mutex.synchronize { @snapshot = nil }
end