Method: Kennel::FileCache#initialize

Defined in:
lib/kennel/file_cache.rb

#initialize(file) ⇒ FileCache

Returns a new instance of FileCache.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kennel/file_cache.rb', line 8

def initialize(file)
  @file = file
  @data =
    begin
      Marshal.load(File.read(@file)) # rubocop:disable Security/MarshalLoad
    rescue StandardError
      {}
    end
  @now = Time.now.to_i
  @expires = @now + (30 * 24 * 60 * 60) # 1 month
  @data.reject! { |_, (_, _, ex)| ex < @now } # expire old data
end