Class: Tml::Cache

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

Instance Method Summary collapse

Instance Method Details

#cache_nameObject



104
105
106
# File 'lib/tml/cache.rb', line 104

def cache_name
  self.class.name.split('::').last
end

#cached_by_source?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/tml/cache.rb', line 92

def cached_by_source?
  true
end

#clear(opts = {}) ⇒ Object



138
139
140
# File 'lib/tml/cache.rb', line 138

def clear(opts = {})
  # do nothing
end

#delete(key, opts = {}) ⇒ Object



130
131
132
# File 'lib/tml/cache.rb', line 130

def delete(key, opts = {})
  # do nothing
end

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  Tml.config.cache[:enabled]
end

#exist?(key, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/tml/cache.rb', line 134

def exist?(key, opts = {})
  false
end

#fetch(key, opts = {}) ⇒ Object



121
122
123
124
# File 'lib/tml/cache.rb', line 121

def fetch(key, opts = {})
  return nil unless block_given?
  yield
end

#info(msg) ⇒ Object



108
109
110
# File 'lib/tml/cache.rb', line 108

def info(msg)
  Tml.logger.info("#{cache_name} - #{msg}")
end

#read_only?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/tml/cache.rb', line 96

def read_only?
  false
end

#reset_versionObject



84
85
86
# File 'lib/tml/cache.rb', line 84

def reset_version
  @version = nil
end

#segmented?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/tml/cache.rb', line 100

def segmented?
  true
end

#store(key, data, opts = {}) ⇒ Object



126
127
128
# File 'lib/tml/cache.rb', line 126

def store(key, data, opts = {})
  # do nothing
end

#update_version(new_version) ⇒ Object



75
76
77
# File 'lib/tml/cache.rb', line 75

def update_version(new_version)
  store(CACHE_VERSION_KEY, {'version' => new_version}, :ttl => 0)
end

#upgrade_versionObject



79
80
81
82
# File 'lib/tml/cache.rb', line 79

def upgrade_version
  update_version((version || Tml.config.cache[:version] || 0).to_i + 1)
  @version = nil
end

#versionObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tml/cache.rb', line 55

def version
  Tml.config.cache[:version] ||= 1

  @version ||= begin
    v = fetch(CACHE_VERSION_KEY) do
      {'version' => Tml.config.cache[:version]}
    end
    v['version']
  end

  @version ||= Tml.config.cache[:version]

  if Tml.config.cache[:version] > @version
    update_version(Tml.config.cache[:version])
    @version = Tml.config.cache[:version]
  end

  @version
end

#versioned_key(key, opts = {}) ⇒ Object



116
117
118
119
# File 'lib/tml/cache.rb', line 116

def versioned_key(key, opts = {})
  return key if CACHE_VERSION_KEY == key
  "tml_rc_v#{version}_#{key}"
end

#warn(msg) ⇒ Object



112
113
114
# File 'lib/tml/cache.rb', line 112

def warn(msg)
  Tml.logger.warn("#{cache_name} - #{msg}")
end