Class: Elephas::Providers::RubyOnRails
- Inherits:
-
Object
- Object
- Elephas::Providers::RubyOnRails
- Includes:
- Base
- Defined in:
- lib/elephas/providers/ruby_on_rails.rb
Overview
This is a Ruby on Rails providers, 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 included from Base
Instance Method Details
- (Boolean) delete(key)
Deletes a value from the cache.
39 40 41 42 43 44 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 39 def delete(key) key = key.ensure_string rv = Rails.cache.exist?(key) Rails.cache.delete(key) rv end |
- (Boolean) exists?(key)
Checks if a key exists in the cache.
50 51 52 53 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 50 def exists?(key) key = key.ensure_string Rails.cache.exist?(key) && Rails.cache.read(key).valid? end |
- (Entry|NilClass) read(key)
Reads a value from the cache.
17 18 19 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 17 def read(key) self.exists?(key) ? Rails.cache.read(key) : nil end |
- (Object) write(key, value, options = {})
Writes a value to the cache.
28 29 30 31 32 33 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 28 def write(key, value, = {}) entry = ::Elephas::Entry.ensure(value, key, ) entry.refresh Rails.cache.write(key, entry, expires_in: entry.ttl) entry end |