Sha256: 70be2b70d4e164a1511d2587eebcc250e2adcb578f80b1dc27ed411f1e507b67

Contents?: true

Size: 1.16 KB

Versions: 44

Compression:

Stored size: 1.16 KB

Contents

require 'active_support/inflector'

module Wovnrb
  class CacheBase
    @@strategy_map = {
        memory: :memory_cache
    }

    @@default_base_config = {
      strategy: :memory
    }

    @@singleton_cache = nil
    def self.get_single
      raise 'cache is not initialized' unless @@singleton_cache
      @@singleton_cache
    end

    def self.set_single(config)
      @@singleton_cache = self.build(config)
    end

    def self.reset_cache
      @@singleton_cache = nil
    end

    def self.build(config)
      @config = @@default_base_config.merge config

      strategy = @@strategy_map[@config[:strategy]]
      raise "Invalid strategy: #{strategy}" unless strategy

      strategy_sym = strategy.to_sym
      begin
        require "wovnrb/text_caches/#{strategy_sym}"
      rescue LoadError => e
        raise "Could not find #{strategy_sym} (#{e})"
      end

      strategy_class = Wovnrb.const_get(ActiveSupport::Inflector.camelize(strategy_sym))
      strategy_class.new(config)
    end

    def put(key, value)
      raise NotImplementedError.new('put is not defined')
    end

    def get(key)
      raise NotImplementedError.new('put is not defined')
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
wovnrb-1.1.0 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.13 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.12 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.11 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.10 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.9 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.8 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.7 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.6 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.5 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.4 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.2 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.1 lib/wovnrb/text_caches/cache_base.rb
wovnrb-1.0.0 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.30 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.29 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.28 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.27 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.26 lib/wovnrb/text_caches/cache_base.rb
wovnrb-0.2.25 lib/wovnrb/text_caches/cache_base.rb