Class: Friendly::Cache::ByID

Inherits:
Friendly::Cache show all
Defined in:
lib/friendly/cache/by_id.rb

Instance Attribute Summary

Attributes inherited from Friendly::Cache

#cache, #fields, #klass, #version

Instance Method Summary collapse

Methods inherited from Friendly::Cache

cache_for, #initialize

Methods inherited from Storage

#count

Constructor Details

This class inherits a constructor from Friendly::Cache

Instance Method Details

#all(query, &block) ⇒ Object



18
19
20
21
# File 'lib/friendly/cache/by_id.rb', line 18

def all(query, &block)
  keys = query.conditions[:id].map { |k| cache_key(k) }
  cache.multiget(keys, &block).values
end

#destroy(document) ⇒ Object



10
11
12
# File 'lib/friendly/cache/by_id.rb', line 10

def destroy(document)
  cache.delete(cache_key(document.id))
end

#first(query, &block) ⇒ Object



14
15
16
# File 'lib/friendly/cache/by_id.rb', line 14

def first(query, &block)
  cache.get(cache_key(query.conditions[:id]), &block)
end

#satisfies?(query) ⇒ Boolean

Returns:



23
24
25
# File 'lib/friendly/cache/by_id.rb', line 23

def satisfies?(query)
  query.conditions.keys == [:id]
end

#store(document) ⇒ Object Also known as: create, update



4
5
6
# File 'lib/friendly/cache/by_id.rb', line 4

def store(document)
  cache.set(cache_key(document.id), document)
end