Class: SuperCache::DogPileFilter
- Inherits:
-
Object
- Object
- SuperCache::DogPileFilter
- Defined in:
- lib/super_cache/dog_pile_filter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#filter(controller, action = nil, &block) ⇒ Object
1.
-
#initialize(options = {}) ⇒ DogPileFilter
constructor
A new instance of DogPileFilter.
Constructor Details
#initialize(options = {}) ⇒ DogPileFilter
Returns a new instance of DogPileFilter.
4 5 6 |
# File 'lib/super_cache/dog_pile_filter.rb', line 4 def initialize(={}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/super_cache/dog_pile_filter.rb', line 3 def @options end |
Instance Method Details
#filter(controller, action = nil, &block) ⇒ Object
-
check the expiration info of target key
-
if target key is expired, add a lock against target key
2.1 if not expired, return the cache 3.1 if lock successfully, then continue to action 3.2 if lock failed, then obtain target key 3.2.1 if target key is missing, then 3.2.1.1 wait for N sec to check if the cache is generated 3.2.1.1.1 if timeout, go to action 3.2.2 target key is not missing, return the cache 3.3 go to the action and obtain response body 3.4 store the response body to the target key and set the expiration with 2x longer 3.5 store the expireation info of target key
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/super_cache/dog_pile_filter.rb', line 19 def filter(controller, action=nil, &block) action ||= block return action.call unless controller.perform_caching = self..dup [:controller] = controller [:action] = action || block [:cache_path] ||= weird_cache_path() [:flag_key] = "expires_at:#{[:cache_path]}" [:expires_in] ||= 600 [:content] = nil if Rails.cache.read([:flag_key], :raw => true) check_cache() else cache_expired() end end |