Permalink
Browse files

#cache?, #cache_configured? and cache_store accessors are now on inst…

…ance level. Caching.expire_cache_key moved to Rails since it is using the global Rails cache store.
  • Loading branch information...
1 parent 8e9c4bc commit fe54adbe35054c9bdede9faad58420f631a430c8 @apotonick apotonick committed Jun 25, 2012
Showing with 25 additions and 20 deletions.
  1. +15 −17 lib/cell/caching.rb
  2. +10 −3 lib/cell/rails.rb
View
@@ -13,8 +13,6 @@ module Caching
end
module ClassMethods
- attr_accessor :cache_store # we want to use DI to set a cache store in cell/rails.
-
# Caches the rendered view of +state+.
#
# Examples:
@@ -67,47 +65,47 @@ def state_cache_key(state, key_parts={})
expand_cache_key([controller_path, state, key_parts])
end
- def expire_cache_key(key, *args)
+ def expire_cache_key_for(key, cache_store, *args)
cache_store.delete(key, *args)
end
- def cache?(state)
- cache_configured? and state_cached?(state)
- end
-
- def cache_configured?
- @cache_configured
- end
- attr_writer :cache_configured
protected
# Compiles cache key and adds :cells namespace to +key+, according to the
# ActiveSupport::Cache.expand_cache_key API.
def expand_cache_key(key)
::ActiveSupport::Cache.expand_cache_key(key, :cells)
end
-
- def state_cached?(state)
- version_procs.has_key?(state)
- end
end
+
def render_state(state, *args)
return super(state, *args) unless cache?(state, *args)
key = self.class.state_cache_key(state, call_state_versioner(state, *args))
options = self.class.cache_options[state]
- self.class.cache_store.fetch(key, options) do
+ cache_store.fetch(key, options) do
super(state, *args)
end
end
+ def cache_configured?
+ @cache_configured
+ end
+ attr_writer :cache_configured
+
+ attr_accessor :cache_store # we want to use DI to set a cache store in cell/rails.
+
def cache?(state, *args)
- self.class.cache?(state) and call_state_conditional(state, *args)
+ cache_configured? and state_cached?(state) and call_state_conditional(state, *args)
end
protected
+ def state_cached?(state)
+ self.class.version_procs.has_key?(state)
+ end
+
def call_proc_or_method(state, method, *args)
return method.call(self, *args) if method.kind_of?(Proc)
send(method, *args)
View
@@ -16,9 +16,8 @@ def cache_store
ActionController::Base.cache_store
end
- def cache_configured?
- # DISCUSS: why is it private?
- ActionController::Base.send(:cache_configured?)
+ def expire_cache_key(key, *args) # FIXME: move to Rails.
+ expire_cache_key_for(key, cache_store ,*args)
end
private
@@ -35,5 +34,13 @@ def initialize(parent_controller)
super
@parent_controller = parent_controller
end
+
+ def cache_configured?
+ ActionController::Base.send(:cache_configured?) # DISCUSS: why is it private?
+ end
+
+ def cache_store
+ self.class.cache_store # in Rails, we have a global cache store.
+ end
end
end

0 comments on commit fe54adb

Please sign in to comment.