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.
218 219 220 221 222 |
# File 'lib/gh-archive.rb', line 218 def initialize(max_size = 10) @cache = {} @max_size = max_size @mutex = Mutex.new end |
Instance Method Details
#full? ⇒ Boolean
246 247 248 |
# File 'lib/gh-archive.rb', line 246 def full? self.size >= @max_size end |
#get(name) ⇒ Object
230 231 232 233 234 |
# File 'lib/gh-archive.rb', line 230 def get(name) @mutex.synchronize do return @cache.delete(name) end end |
#has?(name) ⇒ Boolean
242 243 244 |
# File 'lib/gh-archive.rb', line 242 def has?(name) return @cache.has_key?(name) end |
#put(name, content) ⇒ Object
224 225 226 227 228 |
# File 'lib/gh-archive.rb', line 224 def put(name, content) @mutex.synchronize do @cache[name] = content end end |
#size ⇒ Object
236 237 238 239 240 |
# File 'lib/gh-archive.rb', line 236 def size @mutex.synchronize do return @cache.size end end |