Class: Wovnrb::CacheBase
- Inherits:
-
Object
- Object
- Wovnrb::CacheBase
- Defined in:
- lib/wovnrb/text_caches/cache_base.rb
Direct Known Subclasses
Constant Summary collapse
- @@strategy_map =
{ memory: :memory_cache }
- @@default_base_config =
{ strategy: :memory }
- @@singleton_cache =
nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build(config) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 27 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 |
.get_single ⇒ Object
14 15 16 17 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 14 def self.get_single raise 'cache is not initialized' unless @@singleton_cache @@singleton_cache end |
.reset_cache ⇒ Object
23 24 25 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 23 def self.reset_cache @@singleton_cache = nil end |
.set_single(config) ⇒ Object
19 20 21 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 19 def self.set_single(config) @@singleton_cache = self.build(config) end |
Instance Method Details
#get(key) ⇒ Object
48 49 50 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 48 def get(key) raise NotImplementedError.new('put is not defined') end |
#put(key, value) ⇒ Object
44 45 46 |
# File 'lib/wovnrb/text_caches/cache_base.rb', line 44 def put(key, value) raise NotImplementedError.new('put is not defined') end |