Module: SimpleCache
- Defined in:
- lib/simple_cache.rb,
lib/simple_cache.rb
Defined Under Namespace
Modules: Interface, Marshal, SimplyCached
Classes: MemcachedStore, NullStore, PgStore, RedisStore, SqliteDatabase, SqliteStore
Class Method Summary
collapse
Class Method Details
.cache_key(obj) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/simple_cache.rb', line 98
def self.cache_key(obj)
return SimpleCache::Marshal.md5(obj.cache_key) if obj.respond_to?(:cache_key)
case obj
when String
SimpleCache::Marshal.md5 obj
when Hash
parts = []
obj.each { |k,v| parts << cache_key(k) << cache_key(v) }
SimpleCache::Marshal.md5 parts.join("/")
when Array
parts = obj.map { |part| cache_key(part) }
SimpleCache::Marshal.md5 parts.join(":")
else
SimpleCache::Marshal.md5 self.inspect
end
end
|
.create_store(url) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/simple_cache.rb', line 16
def self.create_store(url)
expect! url => [ "null:", nil, String, Redis, Redis::Namespace ]
klass = case url
when Redis, Redis::Namespace then SimpleCache::RedisStore
when "null:", nil then SimpleCache::NullStore
else
uri = URI.parse(url)
expect! uri.scheme => [ nil, "redis", "sqlite", "pg", "memcached" ]
case uri.scheme
when "redis" then SimpleCache::RedisStore
when nil, "sqlite" then SimpleCache::SqliteStore
when "pg" then SimpleCache::PgStore
when "memcached" then SimpleCache::MemcachedStore
end
end
klass.new url
end
|
.new(url) ⇒ Object
37
38
39
|
# File 'lib/simple_cache.rb', line 37
def self.new(url)
create_store(url).extend SimpleCache::Interface
end
|