Class: Ramaze::SequelCache

Inherits:
Object show all
Defined in:
lib/ramaze/contrib/sequel_cache.rb

Overview

drop-in replacement for Ramaze’s built-in MemoryCache built on the Sequel. to use with sessions do

Ramaze::Global::cache_alternative[:sessions] = Ramaze::SequelCache

to use with everything do

Ramaze::Global::cache = Ramaze::SequelCache

Defined Under Namespace

Classes: Table

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](key) ⇒ Object



34
35
36
37
# File 'lib/ramaze/contrib/sequel_cache.rb', line 34

def self.[] key
  record = Table.find :key => key
  record ? record.value : nil
end

.[]=(key, value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ramaze/contrib/sequel_cache.rb', line 39

def self.[]= key, value
  begin
    Table.create :key => key, :value => value
  rescue
    Table.filter(:key => key).update :value => value
    unless Table.find(:key => key)
      Table.create :key => key, :value => value rescue nil
    end
  end
  # ruby always returns 'value' for []= !
rescue
  nil
end

.clearObject



64
65
66
# File 'lib/ramaze/contrib/sequel_cache.rb', line 64

def self.clear
  Table.delete_all
end

.delete(*keys) ⇒ Object



57
58
59
60
61
62
# File 'lib/ramaze/contrib/sequel_cache.rb', line 57

def self.delete *keys
  keys.map do |key|
    record = Table[key]
    record.delete if record
  end
end

.newObject



68
69
70
# File 'lib/ramaze/contrib/sequel_cache.rb', line 68

def self.new
  self
end

.to_symObject



72
73
74
# File 'lib/ramaze/contrib/sequel_cache.rb', line 72

def self.to_sym
  name.split(%r/::/).last.to_sym
end

.values_at(*keys) ⇒ Object



53
54
55
# File 'lib/ramaze/contrib/sequel_cache.rb', line 53

def self.values_at *keys
  keys.map{|key| Table[key]}
end

Instance Method Details

#tObject



32
# File 'lib/ramaze/contrib/sequel_cache.rb', line 32

def t() Table end

#tableObject



31
# File 'lib/ramaze/contrib/sequel_cache.rb', line 31

def table() Table end