Class: Ultracache::HasCachedQueue
- Inherits:
-
Relationship
- Object
- Relationship
- Ultracache::HasCachedQueue
- Defined in:
- lib/ultracache/relationship/has_cached_queue.rb
Instance Attribute Summary collapse
-
#fetch_by ⇒ Object
readonly
Returns the value of attribute fetch_by.
Attributes inherited from Relationship
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ HasCachedQueue
constructor
A new instance of HasCachedQueue.
- #key(obj) ⇒ Object
-
#read_cache(obj, options = {}) ⇒ Object
Reads caches stored in corresponding queue.
Methods inherited from Relationship
#associated_class, #destroy_cache, #save_cache, #self_class, #update_cache
Constructor Details
#initialize(name, options = {}) ⇒ HasCachedQueue
Returns a new instance of HasCachedQueue.
5 6 7 8 |
# File 'lib/ultracache/relationship/has_cached_queue.rb', line 5 def initialize(name, ={}) @fetch_by = [:fetch_by] super(name, ) end |
Instance Attribute Details
#fetch_by ⇒ Object (readonly)
Returns the value of attribute fetch_by.
3 4 5 |
# File 'lib/ultracache/relationship/has_cached_queue.rb', line 3 def fetch_by @fetch_by end |
Instance Method Details
#key(obj) ⇒ Object
10 11 12 |
# File 'lib/ultracache/relationship/has_cached_queue.rb', line 10 def key(obj) "#{@self_class.to_s.underscore}:#{obj.id}:#{@name}" end |
#read_cache(obj, options = {}) ⇒ Object
Reads caches stored in corresponding queue. Caches can be fetched by their score or their rank.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ultracache/relationship/has_cached_queue.rb', line 16 def read_cache(obj, = {}) k = self.key(obj) fetch_by = @fetch_by || [:fetch_by] if fetch_by && fetch_by == :rank storage.get_queue_by_rank(k, ) elsif [:per_page] storage.get_queue_paged(k, ) else storage.get_queue(k, ) end end |