Class: Everlog::Inf::Cache::File

Inherits:
Everlog::Inf::Cache show all
Defined in:
lib/everlog/inf/cache/file.rb

Direct Known Subclasses

Wunderground

Defined Under Namespace

Classes: Wunderground

Instance Method Summary collapse

Constructor Details

#initializeFile

Returns a new instance of File.



6
7
8
9
# File 'lib/everlog/inf/cache/file.rb', line 6

def initialize
  service = self.class.name.split('::').last.downcase
  @cache = LocalFileCache.new("#{::File.dirname(__FILE__)}/data/#{service}")
end

Instance Method Details

#create(date, proc_args = {}, &api_proc) ⇒ Object



11
12
13
14
15
16
# File 'lib/everlog/inf/cache/file.rb', line 11

def create(date, proc_args = {}, &api_proc)
  return @cache.get(date) if @cache.has?(date)
  data = api_proc.call(proc_args)
  @cache.set(date, data)
  data
end

#delete(key) ⇒ Object



18
19
20
# File 'lib/everlog/inf/cache/file.rb', line 18

def delete key
  @cache.delete key
end

#flushObject



22
23
24
# File 'lib/everlog/inf/cache/file.rb', line 22

def flush
  @cache.flush
end