Class: VSM::Meta::SnapshotCache
- Inherits:
-
Object
- Object
- VSM::Meta::SnapshotCache
- Defined in:
- lib/vsm/meta/snapshot_cache.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(builder) ⇒ SnapshotCache
constructor
A new instance of SnapshotCache.
- #invalidate! ⇒ Object
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
#fetch ⇒ Object
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 |