Module: Telebugs::FileCache
- Defined in:
- lib/telebugs/file_cache.rb
Constant Summary collapse
- MAX_SIZE =
50
- MUTEX =
Mutex.new
Class Method Summary collapse
-
.[](key) ⇒ Object
Retrieve an object from the cache.
-
.[]=(key, value) ⇒ Object
Associates the value given by
value
with the key given bykey
. -
.empty? ⇒ Boolean
Checks whether the cache is empty.
- .reset ⇒ Object
Class Method Details
.[](key) ⇒ Object
Retrieve an object from the cache.
18 19 20 21 22 |
# File 'lib/telebugs/file_cache.rb', line 18 def self.[](key) MUTEX.synchronize do data[key] end end |
.[]=(key, value) ⇒ Object
Associates the value given by value
with the key given by key
. Deletes entries that exceed MAX_SIZE
.
10 11 12 13 14 15 |
# File 'lib/telebugs/file_cache.rb', line 10 def self.[]=(key, value) MUTEX.synchronize do data[key] = value data.delete(data.keys.first) if data.size > MAX_SIZE end end |
.empty? ⇒ Boolean
Checks whether the cache is empty. Needed only for the test suite.
25 26 27 28 29 |
# File 'lib/telebugs/file_cache.rb', line 25 def self.empty? MUTEX.synchronize do data.empty? end end |
.reset ⇒ Object
31 32 33 34 35 |
# File 'lib/telebugs/file_cache.rb', line 31 def self.reset MUTEX.synchronize do @data = {} end end |