/usr/lib/ruby/1.8/ramaze/cache/sequel.rb is in libramaze-ruby1.8 2010.06.18-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.
require 'sequel'
module Ramaze
class Cache
# Cache based on a Sequel model using relational databases.
#
# Please note that this cache might not work perfectly with Sequel 3.0.0,
# as the #[] and #[]= methods do not respect serialization.
# I'll lobby for a change in that direction.
class Sequel
include Cache::API
class Table < ::Sequel::Model(:ramaze_cache)
plugin :schema
plugin :serialization
serialize_attributes :marshal, :value
set_schema do
primary_key :id
index :key, :unique => true
String :key
String :value
Time :expires
end
def [](column)
if column == :value
deserialized_values[column] = deserialize_value(column, @values[column])
else
super
end
end
end
# Setup the table, not suitable for multiple apps yet.
def cache_setup(host, user, app, name)
@namespace = [host, user, app, name].compact.join(':')
Table.create_table?
@store = Table
end
# Wipe out _all_ data in the table, use with care.
def cache_clear
Table.delete
end
# Delete records for given +keys+
def cache_delete(*keys)
super do |key|
record = @store[:key => namespaced(key)]
record.delete if record
end
end
def cache_fetch(key, default = nil)
super{|key| @store[:key => namespaced(key)] }
end
def cache_store(key, value, options = {})
key = namespaced(key)
ttl = options[:ttl]
expires = Time.now + ttl if ttl
record = @store[:key => key].update(:value => value, :expires => expires)
record.value
rescue
record = @store.create(:key => key, :value => value, :expires => expires)
record.value
end
def namespaced(key)
[@namespace, key].join(':')
end
end
end
end
|