Class: Fastentry::Cache
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Fastentry::Cache
show all
- Defined in:
- lib/fastentry.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.for(cache) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/fastentry.rb', line 22
def self.for(cache)
if ::Rails::VERSION::MAJOR >= 5
case cache.class.name
when "ActiveSupport::Cache::FileStore"
DefaultCache.new(cache)
when "ActiveSupport::Cache::MemoryStore"
DefaultCache.new(cache)
when "ActiveSupport::Cache::RedisCacheStore"
RedisCache.new(cache)
when "ActiveSupport::Cache::MemCacheStore"
MemcacheCache.new(cache)
when "ActiveSupport::Cache::DalliStore"
DalliCache.new(cache)
else
raise ArgumentError, 'Unsupported cache type'
end
else
case cache.class.name
when "ActiveSupport::Cache::MemCacheStore"
DalliCache.new(cache)
when "ActiveSupport::Cache::DalliStore"
DalliCache.new(cache)
else
DefaultCache.new(cache)
end
end
end
|
Instance Method Details
#expiration_for(key) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/fastentry.rb', line 9
def expiration_for(key)
expires_at = cache.send(:read_entry, key, {}).expires_at
expires_at.to_s.strip.empty? ? nil : Time.at(expires_at)
rescue StandardError
nil
end
|
#read(key) ⇒ Object
16
17
18
19
20
|
# File 'lib/fastentry.rb', line 16
def read(key)
cache.read(key)
rescue StandardError
nil
end
|