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

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

Returns:

  • (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

Returns:

  • (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

#sizeObject



379
380
381
382
383
# File 'lib/gh-archive.rb', line 379

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