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.
40 41 42 43 44 45 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 40 def delete(key) fkey = key.ensure_string rv = Rails.cache.exist?(fkey) Rails.cache.delete(fkey) rv end |
- (Boolean) exists?(key)
Checks if a key exists in the cache.
51 52 53 54 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 51 def exists?(key) fkey = key.ensure_string Rails.cache.exist?(fkey) && Rails.cache.read(fkey).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.
27 28 29 30 31 32 33 34 |
# File 'lib/elephas/providers/ruby_on_rails.rb', line 27 def write(key, value, = {}) ttl = [[:ttl].to_integer, 0].max fvalue = ::Elephas::Entry.ensure(value, key, ) fvalue.refresh Rails.cache.write(key, value, :expires_in => ttl) value end |