Class: INatGet::App::Server::API::Cache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/inat-get/app/core/api_cache.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(limit = 100) ⇒ Cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Cache.



14
15
16
17
# File 'lib/inat-get/app/core/api_cache.rb', line 14

def initialize limit = 100
  @limit = limit
  @data = {}
end

Instance Method Details

#delete(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/inat-get/app/core/api_cache.rb', line 33

def delete key
  @data.delete key
end

#read(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
# File 'lib/inat-get/app/core/api_cache.rb', line 19

def read key
  return nil unless @data.has_key?(key)
  value = @data.delete key
  @data[key] = value
  value
end

#write(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
# File 'lib/inat-get/app/core/api_cache.rb', line 26

def write key, value
  @data.delete key
  @data[key] = value
  @data.shift if @data.size > @limit
  value
end