Class: OAI::Provider::ActiveRecordCachingWrapper
- Inherits:
-
ActiveRecordWrapper
- Object
- Model
- ActiveRecordWrapper
- OAI::Provider::ActiveRecordCachingWrapper
- Defined in:
- lib/oai/provider/model/activerecord_caching_wrapper.rb
Overview
OAI::Provider::ActiveRecordCachingWrapper
This class wraps an ActiveRecord model and delegates all of the record selection/retrieval to the AR model. It accepts options for specifying the update timestamp field, a timeout, and a limit. The limit option is used for doing pagination with resumption tokens. The timeout is used to expire old tokens from the cache. Default timeout is 12 hours.
The difference between ActiveRecordWrapper and this class is how the pagination is accomplished. ActiveRecordWrapper encodes all the information in the token. That approach should work 99% of the time. If you have an extremely active respository you may want to consider the caching wrapper. The caching wrapper takes the entire result set from a request and caches it in another database table, well tables actually. So the result returned to the client will always be internally consistent.
Instance Attribute Summary collapse
-
#expire ⇒ Object
readonly
Returns the value of attribute expire.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#timestamp_field ⇒ Object
readonly
Returns the value of attribute timestamp_field.
Instance Method Summary collapse
- #find(selector, options = {}) ⇒ Object
-
#initialize(model, options = {}) ⇒ ActiveRecordCachingWrapper
constructor
A new instance of ActiveRecordCachingWrapper.
Methods inherited from ActiveRecordWrapper
#deleted?, #earliest, #last_id, #latest, #sets
Methods inherited from Model
#deleted?, #earliest, #last_id, #latest, #sets
Constructor Details
#initialize(model, options = {}) ⇒ ActiveRecordCachingWrapper
Returns a new instance of ActiveRecordCachingWrapper.
53 54 55 56 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 53 def initialize(model, ={}) @expire = .delete(:timeout) || 12.hours super(model, ) end |
Instance Attribute Details
#expire ⇒ Object (readonly)
Returns the value of attribute expire.
51 52 53 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 51 def expire @expire end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
51 52 53 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 51 def model @model end |
#timestamp_field ⇒ Object (readonly)
Returns the value of attribute timestamp_field.
51 52 53 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 51 def @timestamp_field end |
Instance Method Details
#find(selector, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 58 def find(selector, ={}) sweep_cache return next_set([:resumption_token]) if [:resumption_token] conditions = sql_conditions() if :all == selector total = model.count(:id, :conditions => conditions) if @limit && total > @limit select_partial( ResumptionToken.new(last_id(conditions), .merge({:last => 0}), nil, total)) else model.find(:all, :conditions => conditions) end else model.find(selector, :conditions => conditions) end end |