Class: Friendly::Cache::ByID
Instance Attribute Summary
#cache, #fields, #klass, #version
Instance Method Summary
collapse
cache_for, #initialize
Methods inherited from Storage
#count
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
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
|