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

Modules: PrependMethods Classes: AllStrategy, Cache, OneStrategy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/arturo/feature_caching.rb', line 36

def self.extended(base)
  class << base
    prepend PrependMethods
    attr_accessor :cache_ttl, :feature_cache, :feature_caching_strategy
    attr_writer :extend_cache_on_failure
  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.extend_cache_on_failure = false
  base.feature_cache = Arturo::FeatureCaching::Cache.new
  base.feature_caching_strategy = AllStrategy
end

Instance Method Details

#caches_features?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/arturo/feature_caching.rb', line 55

def caches_features?
  self.cache_ttl.to_i > 0
end

#extend_cache_on_failure?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/arturo/feature_caching.rb', line 51

def extend_cache_on_failure?
  !!@extend_cache_on_failure
end

#warm_cache!Object



59
60
61
# File 'lib/arturo/feature_caching.rb', line 59

def warm_cache!
  to_feature(:fake_feature_to_force_cache_warming)
end