Module: Arturo::FeatureCaching
- Defined in:
- lib/arturo/feature_caching.rb
Overview
To be extended by Arturo::Feature if you want to enable in-memory caching. NB: Arturo’s feature caching only works when using Arturo::Feature.to_feature or when using the helper methods in Arturo and Arturo::FeatureAvailability. NB: if you have multiple application servers, you almost certainly want to clear this cache after each request:
class ApplicationController < ActionController::Base
after_filter { Arturo::Feature.clear_feature_cache }
end
Alternatively, you could redefine Arturo::Feature.feature_cache to use a shared cache like Memcached.
Defined Under Namespace
Classes: AllStrategy, Cache, OneStrategy
Class Method Summary collapse
Instance Method Summary collapse
- #caches_features? ⇒ Boolean
-
#to_feature_with_caching(feature_or_symbol) ⇒ Object
Wraps Arturo::Feature.to_feature with in-memory caching.
- #warm_cache! ⇒ Object
Class Method Details
.extended(base) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/arturo/feature_caching.rb', line 21 def self.extended(base) class << base alias_method_chain :to_feature, :caching attr_accessor :cache_ttl, :feature_cache, :feature_caching_strategy end base.send(:after_save) do |f| f.class.feature_caching_strategy.expire(f.class.feature_cache, f.symbol.to_sym) if f.class.caches_features? end base.cache_ttl = 0 base.feature_cache = Arturo::FeatureCaching::Cache.new base.feature_caching_strategy = AllStrategy end |
Instance Method Details
#caches_features? ⇒ Boolean
34 35 36 |
# File 'lib/arturo/feature_caching.rb', line 34 def caches_features? self.cache_ttl.to_i > 0 end |
#to_feature_with_caching(feature_or_symbol) ⇒ Object
Wraps Arturo::Feature.to_feature with in-memory caching.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/arturo/feature_caching.rb', line 39 def to_feature_with_caching(feature_or_symbol) if !caches_features? to_feature_without_caching(feature_or_symbol) elsif feature_or_symbol.kind_of?(Arturo::Feature) feature_or_symbol else symbol = feature_or_symbol.to_sym feature_caching_strategy.fetch(feature_cache, symbol) { to_feature_without_caching(symbol) } end end |
#warm_cache! ⇒ Object
50 51 52 |
# File 'lib/arturo/feature_caching.rb', line 50 def warm_cache! warn "Deprecated, no longer necessary!" end |