Class: GHArchive::OnlineProvider::Cache
- Inherits:
-
Object
- Object
- GHArchive::OnlineProvider::Cache
- Defined in:
- lib/gh-archive/providers.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.
261 262 263 264 265 |
# File 'lib/gh-archive/providers.rb', line 261 def initialize(max_size = 10) @cache = {} @max_size = max_size @mutex = Mutex.new end |
Instance Method Details
#full? ⇒ Boolean
291 292 293 |
# File 'lib/gh-archive/providers.rb', line 291 def full? self.size >= @max_size end |
#get(name) ⇒ Object
273 274 275 276 277 |
# File 'lib/gh-archive/providers.rb', line 273 def get(name) @mutex.synchronize do return @cache.delete(name) end end |
#has?(name) ⇒ Boolean
285 286 287 288 289 |
# File 'lib/gh-archive/providers.rb', line 285 def has?(name) @mutex.synchronize do return @cache.has_key?(name) end end |
#put(name, content) ⇒ Object
267 268 269 270 271 |
# File 'lib/gh-archive/providers.rb', line 267 def put(name, content) @mutex.synchronize do @cache[name] = content end end |
#size ⇒ Object
279 280 281 282 283 |
# File 'lib/gh-archive/providers.rb', line 279 def size @mutex.synchronize do return @cache.size end end |