aub-cache_advance 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new do |s|
2
- s.version = '1.0.3'
2
+ s.version = '1.0.4'
3
3
  s.date = %q{2009-01-08}
4
4
 
5
5
  s.name = %q{cache_advance}
@@ -3,8 +3,6 @@ module CacheAdvance
3
3
  attr_reader :named_caches
4
4
  attr_reader :qualifiers
5
5
  attr_reader :plugins
6
- attr_accessor :sweeper_type
7
- attr_accessor :cache
8
6
 
9
7
  def initialize
10
8
  @named_caches = {}
@@ -13,9 +11,9 @@ module CacheAdvance
13
11
  end
14
12
 
15
13
  def apply(cache_name, request, options, &block)
16
- cache = @named_caches[cache_name]
17
- raise UnknownNamedCacheException if cache.nil?
18
- cache.value_for(request, options, &block)
14
+ named_cache = @named_caches[cache_name]
15
+ raise UnknownNamedCacheException if named_cache.nil?
16
+ named_cache.value_for(request, options, &block)
19
17
  end
20
18
 
21
19
  def add_qualifier(name, proc)
@@ -27,7 +25,7 @@ module CacheAdvance
27
25
  end
28
26
 
29
27
  def add_named_cache(name, options)
30
- @named_caches[name] = NamedCache.new(name, options, self, cache)
28
+ @named_caches[name] = NamedCache.new(name, options, self, @cache)
31
29
  end
32
30
 
33
31
  def define_caches
@@ -35,13 +33,21 @@ module CacheAdvance
35
33
  end
36
34
 
37
35
  def create_sweepers
38
- sweeper_type.initialize_observed(@named_caches.values.map { |c| c.expiration_types }.flatten.compact.uniq)
36
+ @sweeper_type.initialize_observed(@named_caches.values.map { |c| c.expiration_types }.flatten.compact.uniq)
39
37
  end
40
38
 
41
39
  def expire_for_class(class_name)
42
- @named_caches.values.each do |cache|
43
- cache.expire_for(class_name)
40
+ @named_caches.values.each do |named_cache|
41
+ named_cache.expire_for(class_name)
44
42
  end
45
43
  end
44
+
45
+ def cache_type=(type)
46
+ @cache = type.new
47
+ end
48
+
49
+ def sweeper_type=(type)
50
+ @sweeper_type = type
51
+ end
46
52
  end
47
53
  end
@@ -26,14 +26,16 @@ module CacheAdvance
26
26
  key = key_for(request, options[:key])
27
27
 
28
28
  if (cache = @cache.read(key))
29
- call_plugins('after_read', key, request, cache)
29
+ each_plugin { |p| p.send('after_read', @name, key, request, cache) if p.respond_to?('after_read') }
30
30
  return cache
31
31
  end
32
-
32
+
33
+ each_plugin { |p| p.send('before_render', @name, key, request) if p.respond_to?('before_render') }
33
34
  result = block.call
34
- call_plugins('before_write', key, request, cache)
35
- @cache.write(key, result, rails_options)
36
- call_plugins('after_write', key, request, cache)
35
+ each_plugin { |p| p.send('after_render', @name, key, request, result) if p.respond_to?('after_render') }
36
+ each_plugin { |p| p.send('before_write', @name, key, request, result) if p.respond_to?('before_write') }
37
+ @cache.write(key, result, rails_options)
38
+ each_plugin { |p| p.send('after_write', @name, key, request, result) if p.respond_to?('after_write') }
37
39
 
38
40
  add_to_cached_keys_list(key)
39
41
 
@@ -75,8 +77,10 @@ module CacheAdvance
75
77
 
76
78
  protected
77
79
 
78
- def call_plugins(method, key, request, data)
79
- @cache_set.plugins.each { |p| p.send(method, @name, key, request, data) if p.respond_to?(method) }
80
+ def each_plugin
81
+ @cache_set.plugins.each do |p|
82
+ yield p
83
+ end
80
84
  end
81
85
 
82
86
  def add_to_cached_keys_list(key)
data/rails/init.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'cache_advance'
2
2
  require 'cache_advance/active_record_sweeper'
3
3
  require 'cache_advance/rails_cache'
4
+
5
+ # Setup the sweeper and cache types as appropriate for Rails.
6
+ CacheAdvance::Caches.sweeper_type = CacheAdvance::ActiveRecordSweeper
7
+ CacheAdvance::Caches.cache_type = CacheAdvance::RailsCache
8
+
4
9
  require 'config/caches'
5
10
  require 'dispatcher'
6
11
 
@@ -15,11 +20,7 @@ end
15
20
 
16
21
  # This will get called after the standard rails environment is initialized.
17
22
  config.after_initialize do
18
-
19
- # Setup the sweeper_type and cache as appropriate for Rails.
20
- CacheAdvance::Caches.sweeper_type = CacheAdvance::ActiveRecordSweeper
21
- CacheAdvance::Caches.cache = CacheAdvance::RailsCache.new
22
-
23
+
23
24
  # This hooks the sweepers into the observer system and adds it to the list.
24
25
  CacheAdvance::Caches.create_sweepers
25
26
  ActiveRecord::Base.observers << CacheAdvance::ActiveRecordSweeper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aub-cache_advance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aubrey Holland