Parent

Files

Padrino::Cache::Store::Base

Abstract Cache Store

Public Class Methods

new(options={}) click to toggle source

@private

# File lib/padrino-cache/store/base.rb, line 55
def initialize(options={})
  @never = -1
  self.parser = options[:parser] || :plain
end

Public Instance Methods

parser() click to toggle source

Get the cache parser strategy

By default is plain, otherwise you can set *Marshal* or write your own.

# File lib/padrino-cache/store/base.rb, line 14
def parser
  @_parser
end
parser=(mod) click to toggle source

Set the caching parser strategy

@param value

Module of Padrino::Cache::Parser or any that respond to encode/decode

@example

Padrino.cache.parser = :plain
Padrino.cache.parser = :marshal
# shortcuts for:
Padrino.cache.parser = Padrino::Cache::Parser::Plain
Padrino.cache.parser = Padrino::Cache::Parser::Marshal

You can easily write your own:

@example

require 'oj'
module FastJSONParser
  def self.encode(value)
    OJ.dump(value)
  end

  def self.decode(value)
    Oj.load(value)
  end
end

Padrino.cache_parser = FastJSONParser
# File lib/padrino-cache/store/base.rb, line 47
def parser=(mod)
  mod = Padrino::Cache::Parser.const_get(mod.to_s.camelize) unless mod.is_a?(Module)
  raise "#{mod} should respond to encode" unless mod.respond_to?(:encode)
  raise "#{mod} should respond to decode" unless mod.respond_to?(:decode)
  @_parser=mod
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.