Class: Ultracache::HasCachedQueue

Inherits:
Relationship show all
Defined in:
lib/ultracache/relationship/has_cached_queue.rb

Instance Attribute Summary collapse

Attributes inherited from Relationship

#name

Instance Method Summary collapse

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, options={})
  @fetch_by = options[:fetch_by]
  super(name, options)
end

Instance Attribute Details

#fetch_byObject (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, options = {})
  k = self.key(obj)

  fetch_by = @fetch_by || options[:fetch_by]
  if fetch_by && fetch_by == :rank
    storage.get_queue_by_rank(k, options)
  elsif options[:per_page]
    storage.get_queue_paged(k, options)
  else
    storage.get_queue(k, options)
  end
end