Module: Juno
- Defined in:
- lib/juno.rb,
lib/juno/base.rb,
lib/juno/lock.rb,
lib/juno/cache.rb,
lib/juno/proxy.rb,
lib/juno/stack.rb,
lib/juno/logger.rb,
lib/juno/builder.rb,
lib/juno/expires.rb,
lib/juno/version.rb,
lib/juno/transformer.rb,
lib/juno/adapters/dbm.rb,
lib/juno/adapters/fog.rb,
lib/juno/adapters/file.rb,
lib/juno/adapters/gdbm.rb,
lib/juno/adapters/null.rb,
lib/juno/adapters/riak.rb,
lib/juno/adapters/sdbm.rb,
lib/juno/adapters/yaml.rb,
lib/juno/adapters/couch.rb,
lib/juno/adapters/mongo.rb,
lib/juno/adapters/redis.rb,
lib/juno/adapters/cookie.rb,
lib/juno/adapters/memory.rb,
lib/juno/adapters/pstore.rb,
lib/juno/adapters/sequel.rb,
lib/juno/adapters/sqlite.rb,
lib/juno/adapters/leveldb.rb,
lib/juno/adapters/lruhash.rb,
lib/juno/adapters/cassandra.rb,
lib/juno/adapters/memcached.rb,
lib/juno/adapters/datamapper.rb,
lib/juno/adapters/activerecord.rb,
lib/juno/adapters/tokyocabinet.rb,
lib/juno/adapters/localmemcache.rb,
lib/juno/adapters/memcached_dalli.rb,
lib/juno/adapters/memcached_native.rb
Defined Under Namespace
Modules: Adapters Classes: Base, Builder, Cache, Expires, Lock, Logger, Proxy, Stack, Transformer
Constant Summary collapse
- VERSION =
Juno version number
'0.3.0'
Class Method Summary collapse
-
.build(&block) ⇒ Object
Build your own store chain!.
-
.new(name, options = {}) ⇒ Object
Create new Juno store with default proxies which works in most cases if you don’t want fine control over the proxy chain.
Class Method Details
.build(&block) ⇒ Object
Build your own store chain!
118 119 120 |
# File 'lib/juno.rb', line 118 def self.build(&block) Builder.new(&block).build.last end |
.new(name, options = {}) ⇒ Object
Create new Juno store with default proxies which works in most cases if you don’t want fine control over the proxy chain. It uses Marshal on the keys and values. Use Juno#build if you want to have fine control!
Options:
-
:expires - If true, ensure that store supports expiration by inserting Juno::Expires if the underlying adapter doesn’t support it natively
-
:threadsafe - If true, ensure that the store is thread safe by inserting Juno::Lock
-
:logger - If true or Hash, add logger to chain (Hash is passed to logger as options)
-
:compress - If true, compress value with zlib, or specify custom compress, e.g. :quicklz
-
:serializer - Serializer used for key and value (default :marshal, disable with nil)
-
:key_serializer - Serializer used for key (default options)
-
:value_serializer - Serializer used for key (default options)
-
:prefix - Key prefix used for namespacing (default none)
-
All other options passed to the adapter
Supported adapters:
-
:HashFile (Store which spreads the entries using a md5 hash, e.g. cache/42/391dd7535aebef91b823286ac67fcd)
-
:File (normal file store)
-
:Memcached (Memcached store)
-
… (All other adapters from Juno::Adapters)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/juno.rb', line 66 def self.new(name, = {}) expires = .delete(:expires) logger = .delete(:logger) threadsafe = .delete(:threadsafe) compress = .delete(:compress) serializer = .delete(:serializer) || :marshal key_serializer = .delete(:key_serializer) || serializer value_serializer = .delete(:value_serializer) || serializer transformer = { :key => [key_serializer], :value => [value_serializer], :prefix => .delete(:prefix) } transformer[:key] << :prefix if transformer[:prefix] transformer[:value] << (Symbol === compress ? compress : :zlib) if compress raise ArgumentError, 'Name must be Symbol' unless Symbol === name case name when :Sequel, :ActiveRecord, :Couch # Sequel accept only base64 keys and values # FIXME: Couch should work only with :marshal but this raises an error on 1.9 transformer[:key] << :base64 transformer[:value] << :base64 when :Memcached, :MemcachedDalli, :MemcachedNative # Memcached accept only base64 keys, expires already supported expires = false transformer[:key] << :base64 when :PStore, :YAML, :DataMapper, :Null # For PStore, YAML and DataMapper only the key has to be a string transformer.delete(:value) if transformer[:value] == [:marshal] when :HashFile # Use spreading hashes transformer[:key] << :md5 << :spread name = :File when :File # Use escaping transformer[:key] << :escape when :Cassandra, :Redis # Expires already supported expires = false end build do use :Logger, Hash === logger ? logger : {} if logger use :Expires if expires use :Transformer, transformer use :Lock if threadsafe adapter name, end end |