Sha256: fdf46672839816b0ee92f6a47315c36a2477d10d8a2fdfcf02486fb0a12ebdd2

Contents?: true

Size: 1.18 KB

Versions: 19

Compression:

Stored size: 1.18 KB

Contents

require "set"
require "fileutils"
require "libcache"

class DefaultCache < Cache

  attr_accessor :logger

  def initialize(logger = nil)

    if logger != nil

      @logger = logger
    else

      @logger = Logger.new(STDOUT)
    end

    @keys = Set[]
    @capacity = 10 * 1000

    lambda = lambda { |*key| @logger.debug "Retrieved #{key}" }

    @in_memory = CacheBuilder.with(Cache)
                             .set_max(@capacity)
                             .set_post_get(lambda)
                             .build
  end

  def verify
    @in_memory != nil && @capacity > 0
  end

  def set(key, value)

    begin
      @in_memory.put(key, value)

    rescue ArgumentError => e

      @logger.error "ERROR: " + e.to_s

      raise "Invalid arguments passed to the 'set' method: key='" + key.to_s + "', value='" + value.to_s + "'"
    end
  end

  def get(key)

    value = @in_memory.get(key)
    value
  end

  def delete(key)

    if key == nil

      raise "Key is nil"
    end

    if @in_memory.exists?(key)

      @in_memory.invalidate(key)
    end

    @keys.delete(key)
  end

  def keys

    @keys
  end

  private

  def directory_exists?(directory)

    File.directory?(directory)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ff-ruby-server-sdk-1.4.6 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.5 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.4 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.3 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.2 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.1 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.4.0 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.3.2 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.3.1 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.2.1 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.2.0 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.1.4 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.1.3 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.1.2 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.1.1 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.1.0 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.0.6 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.0.5 lib/ff/ruby/server/sdk/api/default_cache.rb
ff-ruby-server-sdk-1.0.4 lib/ff/ruby/server/sdk/api/default_cache.rb