Class: CacheAdvance::CacheSet

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_advance/cache_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_cachesObject (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

#pluginsObject (readonly)

Returns the value of attribute plugins.



5
6
7
# File 'lib/cache_advance/cache_set.rb', line 5

def plugins
  @plugins
end

#qualifiersObject (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, options)
  @named_caches[name] = NamedCache.new(name, options, 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, options, &block)
  if CacheAdvance.caching_enabled
    named_cache = @named_caches[cache_name]
    raise UnknownNamedCacheException if named_cache.nil?
    named_cache.value_for(request, options, &block)
  else
    block.call
  end
end

#create_sweepersObject



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

Yields:



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_completeObject



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