Class: OnlineGHAProvider::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/gh-archive.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 10) ⇒ Cache



365
366
367
368
369
# File 'lib/gh-archive.rb', line 365

def initialize(max_size = 10)
    @cache = {}
    @max_size = max_size
    @mutex = Mutex.new
end

Instance Method Details

#full?Boolean



393
394
395
# File 'lib/gh-archive.rb', line 393

def full?
    self.size >= @max_size
end

#get(name) ⇒ Object



377
378
379
380
381
# File 'lib/gh-archive.rb', line 377

def get(name)
    @mutex.synchronize do
        return @cache.delete(name)
    end
end

#has?(name) ⇒ Boolean



389
390
391
# File 'lib/gh-archive.rb', line 389

def has?(name)
    return @cache.has_key?(name)
end

#put(name, content) ⇒ Object



371
372
373
374
375
# File 'lib/gh-archive.rb', line 371

def put(name, content)
    @mutex.synchronize do
        @cache[name] = content
    end
end

#sizeObject



383
384
385
386
387
# File 'lib/gh-archive.rb', line 383

def size
    @mutex.synchronize do
        return @cache.size
    end
end