Class: Contrast::Utils::Assess::ObjectStore
- Defined in:
- lib/contrast/utils/assess/object_store.rb
Overview
keep track of object properties and events data
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
We would keep object ids with capacity.
- #delete(key) ⇒ Object
- #get ⇒ Object
-
#initialize(capacity = 500) ⇒ ObjectStore
constructor
A new instance of ObjectStore.
Constructor Details
#initialize(capacity = 500) ⇒ ObjectStore
Returns a new instance of ObjectStore.
9 10 11 12 |
# File 'lib/contrast/utils/assess/object_store.rb', line 9 def initialize capacity = 500 @capacity = capacity @cache = {} end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/contrast/utils/assess/object_store.rb', line 18 def [] key @cache[key] end |
#[]=(key, value) ⇒ Object
We would keep object ids with capacity. If a reference is kept to an object only by it’s id, It would be CG-ted safely.
29 30 31 32 |
# File 'lib/contrast/utils/assess/object_store.rb', line 29 def []= key, value @cache[key] = value @cache.shift if @cache.length > @capacity end |
#delete(key) ⇒ Object
22 23 24 |
# File 'lib/contrast/utils/assess/object_store.rb', line 22 def delete key @cache.delete(key) end |
#get ⇒ Object
14 15 16 |
# File 'lib/contrast/utils/assess/object_store.rb', line 14 def get @cache end |