Sha256: f1a947134d02b030c76ea6a203044c5a1d91ff69c218c5d97017f6b4a1031996

Contents?: true

Size: 765 Bytes

Versions: 1

Compression:

Stored size: 765 Bytes

Contents

require_relative 'cache'

class FileCache < Cache

  def initialize
    super
  end

  def create_store
    @cache = Hash.new
    if store == nil
      raise 'Store path is missing!'
    end
  end

  def put(key, value)
    @cache[key] = value
    File.open(File.join(store, key.to_s), 'w') do |f|
      f.write(value)
    end
    @scheduler.in expiry_time, :blocking => true do
      invalidate key
    end
  end

  def get(key)
    refresh
    return File.read(File.join(store, key.to_s))
  end

  def invalidate(key)
    super
    File.delete(File.join(store, key.to_s))
  end

  def invalidateAll
    super
    Dir.foreach(store) do |f|
      File.delete(File.join(store, f)) if f != '.' && f != '..'
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libcache-0.2.0 lib/libcache/file_cache.rb