Class: Store::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/store/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend_store, args = {}) ⇒ Cache

Returns a new instance of Cache.



8
9
10
11
12
13
14
15
# File 'lib/store/cache.rb', line 8

def initialize backend_store, args={}
  @backend = backend_store
  if args[:memcached]
    @cache = Caches::Memcached.new
  else
    @cache = Caches::InMemory.new
  end
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



6
7
8
# File 'lib/store/cache.rb', line 6

def backend
  @backend
end

Instance Method Details

#all(table) ⇒ Object



40
41
42
# File 'lib/store/cache.rb', line 40

def all table
  each(table).map{|i|i}
end

#closeObject



25
26
27
28
# File 'lib/store/cache.rb', line 25

def close
  @cache.invalidate
  backend.close
end

#collate(*args) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/store/cache.rb', line 74

def collate *args
  key = Marshal.dump(args)
  if data=@cache.load(key)
    data
  else
    data = backend.collate(*args)
    @cache.save(key,data)
    data
  end
end

#count(table) ⇒ Object



44
45
46
# File 'lib/store/cache.rb', line 44

def count table
  backend.count(table)
end

#create(*args) ⇒ Object



30
31
32
33
# File 'lib/store/cache.rb', line 30

def create *args
  @cache.invalidate
  backend.create *args
end

#create_equal_filter(*args) ⇒ Object



85
86
87
# File 'lib/store/cache.rb', line 85

def create_equal_filter *args
  backend.create_equal_filter(*args)
end

#create_gt_filter(*args) ⇒ Object



91
92
93
# File 'lib/store/cache.rb', line 91

def create_gt_filter *args
  backend.create_gt_filter(*args)
end

#create_gte_filter(*args) ⇒ Object



94
95
96
# File 'lib/store/cache.rb', line 94

def create_gte_filter *args
  backend.create_gte_filter(*args)
end

#create_lt_filter(*args) ⇒ Object



88
89
90
# File 'lib/store/cache.rb', line 88

def create_lt_filter *args
  backend.create_lt_filter(*args)
end

#each(table) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/store/cache.rb', line 48

def each table
  if data=@cache.load(table)
    data
  else
    data = backend.all(table)
    @cache.save table, data
    data
  end
end

#find(*args) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/store/cache.rb', line 63

def find *args
  key = Marshal.dump(args)
  if data=@cache.load(key)
    data
  else
    data = backend.find(*args)
    @cache.save key, data
    data
  end
end

#reset(*args) ⇒ Object



58
59
60
61
# File 'lib/store/cache.rb', line 58

def reset *args
  @cache.invalidate
  backend.reset(*args)
end

#timestamperObject



21
22
23
# File 'lib/store/cache.rb', line 21

def timestamper
  backend.timestamper
end

#timestamper=(ts) ⇒ Object



17
18
19
# File 'lib/store/cache.rb', line 17

def timestamper= ts
  backend.timestamper = ts
end

#update(*args) ⇒ Object



35
36
37
38
# File 'lib/store/cache.rb', line 35

def update *args
  @cache.invalidate
  backend.update *args
end