Class: OAI::Provider::ActiveRecordCachingWrapper
- Inherits:
-
ActiveRecordWrapper
- Object
- Model
- ActiveRecordWrapper
- OAI::Provider::ActiveRecordCachingWrapper
- Defined in:
- lib/oai/provider/model/activerecord_caching_wrapper.rb
Overview
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.
Attributes inherited from ActiveRecordWrapper
Attributes inherited from Model
Instance Method Summary collapse
- #find(selector, options = {}) ⇒ Object
-
#initialize(model, options = {}) ⇒ ActiveRecordCachingWrapper
constructor
A new instance of ActiveRecordCachingWrapper.
Methods inherited from ActiveRecordWrapper
#deleted?, #earliest, #latest, #method_missing, #respond_to?, #sets
Methods inherited from Model
#about, #deleted?, #earliest, #latest, #sets
Constructor Details
#initialize(model, options = {}) ⇒ ActiveRecordCachingWrapper
Returns a new instance of ActiveRecordCachingWrapper.
51 52 53 54 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 51 def initialize(model, ={}) @expire = .delete(:timeout) || 12.hours super(model, ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OAI::Provider::ActiveRecordWrapper
Instance Attribute Details
#expire ⇒ Object (readonly)
Returns the value of attribute expire.
49 50 51 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 49 def expire @expire end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
49 50 51 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 49 def model @model end |
#timestamp_field ⇒ Object (readonly)
Returns the value of attribute timestamp_field.
49 50 51 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 49 def @timestamp_field end |
Instance Method Details
#find(selector, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/oai/provider/model/activerecord_caching_wrapper.rb', line 56 def find(selector, ={}) sweep_cache return next_set([:resumption_token]) if [:resumption_token] conditions = sql_conditions() if :all == selector total = model.where(conditions).count if @limit && total > @limit select_partial( ResumptionToken.new(.merge({:last => 0}))) else model.where(conditions) end else model.where(conditions).find(selector) end end |