Class: Elephas::Backends::RubyOnRails
- Inherits:
-
Base
- Object
- Base
- Elephas::Backends::RubyOnRails
- Defined in:
- lib/elephas/backends/ruby_on_rails.rb
Overview
This is a Ruby on Rails backend, which uses Rails.cache.
Instance Method Summary (collapse)
-
- (Boolean) delete(key)
Deletes a value from the cache.
-
- (Boolean) exists?(key)
Checks if a key exists in the cache.
-
- (Entry|NilClass) read(key)
Reads a value from the cache.
-
- (Object) write(key, value, options = {})
Writes a value to the cache.
Methods inherited from Base
Instance Method Details
- (Boolean) delete(key)
Deletes a value from the cache.
37 38 39 40 41 |
# File 'lib/elephas/backends/ruby_on_rails.rb', line 37 def delete(key) rv = Rails.cache.exist?(key) Rails.cache.delete(key) rv end |
- (Boolean) exists?(key)
Checks if a key exists in the cache.
47 48 49 |
# File 'lib/elephas/backends/ruby_on_rails.rb', line 47 def exists?(key) Rails.cache.exist?(key) && Rails.cache.read(key).valid?(self) end |
- (Entry|NilClass) read(key)
Reads a value from the cache.
15 16 17 |
# File 'lib/elephas/backends/ruby_on_rails.rb', line 15 def read(key) exists?(key) ? Rails.cache.read(key) : nil end |
- (Object) write(key, value, options = {})
Writes a value to the cache.
26 27 28 29 30 31 |
# File 'lib/elephas/backends/ruby_on_rails.rb', line 26 def write(key, value, = {}) entry = ::Elephas::Entry.ensure(value, key, ) entry.refresh Rails.cache.write(key, entry, expires_in: entry.ttl) entry end |