Class: CacheAdvance::CacheSet
- Inherits:
-
Object
- Object
- CacheAdvance::CacheSet
- Defined in:
- lib/cache_advance/cache_set.rb
Instance Attribute Summary collapse
-
#named_caches ⇒ Object
readonly
Returns the value of attribute named_caches.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#qualifiers ⇒ Object
readonly
Returns the value of attribute qualifiers.
Instance Method Summary collapse
- #add_named_cache(name, options) ⇒ Object
- #add_plugin(plugin) ⇒ Object
- #add_qualifier(name, proc) ⇒ Object
- #apply(cache_name, request, options, &block) ⇒ Object
- #create_sweepers ⇒ Object
- #define_caches {|Mapper.new(self)| ... } ⇒ Object
- #expire_for_class(class_name) ⇒ Object
-
#initialize(store) ⇒ CacheSet
constructor
A new instance of CacheSet.
- #setup_complete ⇒ Object
- #sweeper_type=(type) ⇒ Object
Constructor Details
#initialize(store) ⇒ CacheSet
Returns a new instance of CacheSet.
7 8 9 |
# File 'lib/cache_advance/cache_set.rb', line 7 def initialize(store) @store, @named_caches, @qualifiers, @plugins = store, {}, {}, [] end |
Instance Attribute Details
#named_caches ⇒ Object (readonly)
Returns the value of attribute named_caches.
3 4 5 |
# File 'lib/cache_advance/cache_set.rb', line 3 def named_caches @named_caches end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
5 6 7 |
# File 'lib/cache_advance/cache_set.rb', line 5 def plugins @plugins end |
#qualifiers ⇒ Object (readonly)
Returns the value of attribute qualifiers.
4 5 6 |
# File 'lib/cache_advance/cache_set.rb', line 4 def qualifiers @qualifiers end |
Instance Method Details
#add_named_cache(name, options) ⇒ Object
33 34 35 |
# File 'lib/cache_advance/cache_set.rb', line 33 def add_named_cache(name, ) @named_caches[name] = NamedCache.new(name, , self, @store) end |
#add_plugin(plugin) ⇒ Object
29 30 31 |
# File 'lib/cache_advance/cache_set.rb', line 29 def add_plugin(plugin) @plugins << plugin end |
#add_qualifier(name, proc) ⇒ Object
25 26 27 |
# File 'lib/cache_advance/cache_set.rb', line 25 def add_qualifier(name, proc) @qualifiers[name] = proc end |
#apply(cache_name, request, options, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/cache_advance/cache_set.rb', line 15 def apply(cache_name, request, , &block) if CacheAdvance.caching_enabled named_cache = @named_caches[cache_name] raise UnknownNamedCacheException if named_cache.nil? named_cache.value_for(request, , &block) else block.call end end |
#create_sweepers ⇒ Object
41 42 43 |
# File 'lib/cache_advance/cache_set.rb', line 41 def create_sweepers @sweeper_type.initialize_observed(@named_caches.values.map { |c| c.expiration_types }.flatten.compact.uniq) end |
#define_caches {|Mapper.new(self)| ... } ⇒ Object
37 38 39 |
# File 'lib/cache_advance/cache_set.rb', line 37 def define_caches yield Mapper.new(self) end |
#expire_for_class(class_name) ⇒ Object
45 46 47 48 49 |
# File 'lib/cache_advance/cache_set.rb', line 45 def expire_for_class(class_name) @named_caches.values.each do |named_cache| named_cache.expire_for(class_name) end end |
#setup_complete ⇒ Object
11 12 13 |
# File 'lib/cache_advance/cache_set.rb', line 11 def setup_complete end |
#sweeper_type=(type) ⇒ Object
51 52 53 |
# File 'lib/cache_advance/cache_set.rb', line 51 def sweeper_type=(type) @sweeper_type = type end |