Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cache Parser Strategy. Fix #821
Now different than before the we store data as plain text, otherwise we bundle also the marshal serializer or you can simply provide yours. Example: Padrino.cache = Padrino::Cache::File.new(...) Padrino.cache.parser # => Padrino::Cache::Parser:Plain Padrino.cache.parser = :marshal Or you can write your own: require 'oj' module PadrinoJSON def self.encode(code) Oj.dump(code) end def self.decode(code) Oj.load(code) end end Finally you can load your strategy: Padrino.cache.parser = PadrinoJSON Or if you prefer do something on the fight you can: Padrino.cache.parser = Module.new do def self.encode end def self.decode end end //cc @padrino/core-members
- Loading branch information
Showing
13 changed files
with
171 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
module Padrino | |||
module Cache | |||
module Store | |||
## | |||
# Abstract Cache Store | |||
# | |||
class Base | |||
|
|||
## | |||
# Get the cache parser strategy | |||
# | |||
# By default is plain, otherwise you can set **Marshal** or write your own. | |||
# | |||
def parser | |||
@_parser | |||
end | |||
|
|||
## | |||
# 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 | |||
# | |||
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 | |||
|
|||
# @private | |||
def initialize(options={}) | |||
self.parser = options[:parser] || :plain | |||
end | |||
|
|||
end # Base | |||
end # Store | |||
end # Cache | |||
end # Padrino | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.