def cache_store(key, value, options = {})
nkey = namespaced(key)
if options[:ttl]
ttl = options[:ttl]
else
ttl = Ramaze::Cache::Sequel.options[:ttl]
end
expires = Time.now + ttl if ttl
if @dataset.filter(:key => nkey).count == 1
serialized_value = serialize(value)
if serialized_value
@dataset.update(:value => serialize(value), :expires => expires)
end
else
serialized_value = serialize(value)
if serialized_value
@dataset.insert(
:key => nkey, :value => serialize(value), :expires => expires
)
end
end
deserialized = deserialize(@dataset.select(:value) \
.filter(:key => nkey) \
.limit(1).first[:value])
if deserialized
return deserialized
else
return value
end
end