Class: Cachetastic::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/cachetastic/cache.rb,
lib/cachetastic/store_object.rb

Defined Under Namespace

Classes: StoreObject

Class Method Summary collapse

Class Method Details

.adapterObject

expire_all



33
34
35
36
37
38
# File 'lib/cachetastic/cache.rb', line 33

def adapter
  unless @_adapter && @_adapter.valid?
    @_adapter = Cachetastic::Adapters.build(cache_klass)
  end
  @_adapter
end

.cache_klassObject



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

def cache_klass
  self
end

.clear_adapter!Object

adapter



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

def clear_adapter!
  @_adapter = nil
end

.delete(key) ⇒ Object

set



19
20
21
22
23
24
# File 'lib/cachetastic/cache.rb', line 19

def delete(key)
  do_with_logging(:delete, key) do
    self.adapter.delete(key)
    nil
  end
end

.expire_allObject

delete



26
27
28
29
30
31
# File 'lib/cachetastic/cache.rb', line 26

def expire_all
  do_with_logging(:expire_all, nil) do
    self.adapter.expire_all
    nil
  end
end

.get(key, &block) ⇒ Object



6
7
8
9
10
11
# File 'lib/cachetastic/cache.rb', line 6

def get(key, &block)
  do_with_logging(:get, key) do
    val = self.adapter.get(key, &block)
    handle_store_object(key, adapter.unmarshal(val), &block)
  end
end

.loggerObject



48
49
50
51
52
53
# File 'lib/cachetastic/cache.rb', line 48

def logger
  unless @_logger
    @_logger = Cachetastic::Logger.new(adapter.logger)
  end
  @_logger
end

.set(key, value, expiry_time = nil) ⇒ Object

get



13
14
15
16
17
# File 'lib/cachetastic/cache.rb', line 13

def set(key, value, expiry_time = nil)
  do_with_logging(:set, key) do
    self.adapter.set(key, value, calculate_expiry_time(expiry_time))
  end
end