Class: GCoder::Storage::RailsCacheAdapter
- Inherits:
-
Adapter
- Object
- Adapter
- GCoder::Storage::RailsCacheAdapter
show all
- Defined in:
- lib/gcoder/storage.rb
Instance Method Summary
collapse
Methods inherited from Adapter
#config, #initialize
Instance Method Details
#clear ⇒ Object
107
108
109
|
# File 'lib/gcoder/storage.rb', line 107
def clear
@cache.keys(@keyspace + '*').each { |key| @cache.del(key) }
end
|
#connect ⇒ Object
102
103
104
105
|
# File 'lib/gcoder/storage.rb', line 102
def connect
@cache = Rails.cache
@keyspace = "#{config[:keyspace] || 'gcoder'}:"
end
|
#get(key) ⇒ Object
111
112
113
|
# File 'lib/gcoder/storage.rb', line 111
def get(key)
@cache.read(keyns(key))
end
|
#set(key, value) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/gcoder/storage.rb', line 115
def set(key, value)
if (ttl = config[:key_ttl])
@cache.write(keyns(key), nval(value), :expires_in => ttl)
else
@cache.write(keyns(key), nval(value))
end
end
|