Module: Kashmir::Caching
- Defined in:
- lib/kashmir/caching.rb,
lib/kashmir/plugins/null_caching.rb,
lib/kashmir/plugins/memory_caching.rb,
lib/kashmir/plugins/memcached_caching.rb
Defined Under Namespace
Classes: Memcached, Memory, Null
Class Method Summary
collapse
-
.bulk_from_cache(representation_definition, objects) ⇒ Object
-
.bulk_write(representation_definition, representations, objects, ttl) ⇒ Object
-
.from_cache(representation_definition, object) ⇒ Object
-
.log(message, level = :info) ⇒ Object
-
.log_key(object, representation_definition) ⇒ Object
-
.store_presenter(representation_definition, representation, object, ttl) ⇒ Object
Class Method Details
.bulk_from_cache(representation_definition, objects) ⇒ Object
21
22
23
24
25
|
# File 'lib/kashmir/caching.rb', line 21
def bulk_from_cache(representation_definition, objects)
class_name = objects.length > 0 ? objects.first.class.to_s : ''
log("read_multi: [#{objects.length}]#{class_name} : #{representation_definition}", :debug)
Kashmir.caching.bulk_from_cache(representation_definition, objects)
end
|
.bulk_write(representation_definition, representations, objects, ttl) ⇒ Object
32
33
34
35
36
|
# File 'lib/kashmir/caching.rb', line 32
def bulk_write(representation_definition, representations, objects, ttl)
class_name = objects.length > 0 ? objects.first.class.to_s : ''
log("write_multi: TTL: #{ttl}: [#{objects.length}]#{class_name} : #{representation_definition}", :debug)
Kashmir.caching.bulk_write(representation_definition, representations, objects, ttl)
end
|
.from_cache(representation_definition, object) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/kashmir/caching.rb', line 7
def from_cache(representation_definition, object)
log("read: #{log_key(object, representation_definition)}", :debug)
cached_representation = Kashmir.caching.from_cache(representation_definition, object)
if cached_representation
log("hit: #{log_key(object, representation_definition)}")
else
log("miss: #{log_key(object, representation_definition)}")
end
cached_representation
end
|
.log(message, level = :info) ⇒ Object
42
43
44
|
# File 'lib/kashmir/caching.rb', line 42
def log(message, level=:info)
Kashmir.logger.send(level, ("\nKashmir::Caching #{message}\n"))
end
|
.log_key(object, representation_definition) ⇒ Object
38
39
40
|
# File 'lib/kashmir/caching.rb', line 38
def log_key(object, representation_definition)
"#{object.class.name}-#{object.id}-#{representation_definition}"
end
|
.store_presenter(representation_definition, representation, object, ttl) ⇒ Object
27
28
29
30
|
# File 'lib/kashmir/caching.rb', line 27
def store_presenter(representation_definition, representation, object, ttl)
log("write TTL: #{ttl}: #{log_key(object, representation_definition)}", :debug)
Kashmir.caching.store_presenter(representation_definition, representation, object, ttl)
end
|