Class: OnlineGHAProvider::Cache
- Inherits:
-
Object
- Object
- OnlineGHAProvider::Cache
- Defined in:
- lib/gh-archive.rb
Instance Method Summary collapse
- #full? ⇒ Boolean
- #get(name) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize(max_size = 10) ⇒ Cache
constructor
A new instance of Cache.
- #put(name, content) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(max_size = 10) ⇒ Cache
Returns a new instance of Cache.
361 362 363 364 365 |
# File 'lib/gh-archive.rb', line 361 def initialize(max_size = 10) @cache = {} @max_size = max_size @mutex = Mutex.new end |
Instance Method Details
#full? ⇒ Boolean
389 390 391 |
# File 'lib/gh-archive.rb', line 389 def full? self.size >= @max_size end |
#get(name) ⇒ Object
373 374 375 376 377 |
# File 'lib/gh-archive.rb', line 373 def get(name) @mutex.synchronize do return @cache.delete(name) end end |
#has?(name) ⇒ Boolean
385 386 387 |
# File 'lib/gh-archive.rb', line 385 def has?(name) return @cache.has_key?(name) end |
#put(name, content) ⇒ Object
367 368 369 370 371 |
# File 'lib/gh-archive.rb', line 367 def put(name, content) @mutex.synchronize do @cache[name] = content end end |
#size ⇒ Object
379 380 381 382 383 |
# File 'lib/gh-archive.rb', line 379 def size @mutex.synchronize do return @cache.size end end |