layercake 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Peter Haza
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ # LayerCake
2
+
3
+ ## Description
4
+ LayerCake is a simple gem that allows you to specify more than one cache store in rails.
5
+ It is built on the idea that memory store is the most efficient store with no network or file overhead, but serves multi-process or multi-server architectures, hence a fallback like filestore or memcached store is necessary.
6
+
7
+ ## Installation
8
+
9
+ The order of the arguments are defining the layers, where the first ones are on the lowest/closest levels.
10
+ `ActionController::Base.cache_store = Layercake::Store.new(:memory_store, :mem_cache_store => ['localhost', 11211])`
11
+
12
+ Use it like you would normally use any cache store.
13
+ `Rails.cache.fetch`
14
+ `Rails.cache.write`
15
+ `Rails.cache.read`
16
+ all the options given will be passed on to the individual cache stores
17
+
18
+ ## Tests
19
+ If you write, I'll merge
20
+
21
+ ## Note on Patches/Pull Requests
22
+
23
+ * Fork the project.
24
+ * Make your feature addition or bug fix.
25
+ * Add tests for it. This is important so I don't break it in a
26
+ future version unintentionally.
27
+ * Commit, do not mess with rakefile, version, or history.
28
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
29
+ * Send me a pull request. Bonus points for topic branches.
30
+
31
+ ## Copyright
32
+
33
+ Copyright (c) 2010 Peter Haza. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "layercake"
8
+ gem.summary = %Q{Support for multiple cache stores in rails, typically memory and/or file and memcached}
9
+ gem.description = %Q{LayerCake is a simple gem that allows you to specify more than one cache store in rails.
10
+ It is built on the idea that memory store is the most efficient store with no network or file overhead, but serves multi-process or multi-server architectures, hence a fallback like filestore or memcached store is necessary.}
11
+ gem.email = "peter.haza@gmail.com"
12
+ gem.homepage = "http://github.com/phaza/layercake"
13
+ gem.authors = ["Peter Haza"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "layercake #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/layercake.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{layercake}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Peter Haza"]
12
+ s.date = %q{2010-10-08}
13
+ s.description = %q{LayerCake is a simple gem that allows you to specify more than one cache store in rails.
14
+ It is built on the idea that memory store is the most efficient store with no network or file overhead, but serves multi-process or multi-server architectures, hence a fallback like filestore or memcached store is necessary.}
15
+ s.email = %q{peter.haza@gmail.com}
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "layercake.gemspec",
28
+ "lib/layercake.rb",
29
+ "lib/layercake/store.rb",
30
+ "test/helper.rb",
31
+ "test/test_layercake.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/phaza/layercake}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Support for multiple cache stores in rails, typically memory and/or file and memcached}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/test_layercake.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,81 @@
1
+ module Layercake
2
+ class Store < ActiveSupport::Cache::Store
3
+
4
+ attr_reader :stores
5
+
6
+ def initialize(*args)
7
+ super()
8
+ @stores = []
9
+
10
+ args.each do |arg|
11
+ initialize_store(arg)
12
+ end
13
+ end
14
+
15
+
16
+ def clear(options = nil)
17
+ @stores.each{|store| store.clear(options) }
18
+ end
19
+
20
+ def cleanup(options = nil)
21
+ @stores.each{|store| store.cleanup(options)}
22
+ end
23
+
24
+ def increment(name, amount = 1, options = nil)
25
+ @stores.map{|store| store.increment(name, amount, options)}.first
26
+ end
27
+
28
+ def decrement(name, amount = 1, options = nil)
29
+ @stores.map{|store| store.decrement(name, amount, options)}.first
30
+ end
31
+
32
+ def delete_matched(matcher, options = nil)
33
+ @stores.each{|store| store.delete_matched(matcher, options)}
34
+ end
35
+
36
+
37
+ protected
38
+ def read_entry(key, options)
39
+ value = nil
40
+ missed = []
41
+
42
+ @stores.each do |store|
43
+ value = store.send(:read_entry, key, options)
44
+ unless value.nil?
45
+ # Rails.logger.debug "Read from: #{store.class}"
46
+ break
47
+ end
48
+
49
+ missed << store
50
+ end
51
+
52
+ if value
53
+ missed.each do |store|
54
+ store.send(:write_entry, key, value, options)
55
+ end
56
+ end
57
+
58
+ value
59
+ end
60
+
61
+ def write_entry(key, entry, options)
62
+ @stores.each{|store| store.send(:write_entry, key, entry, options) }
63
+ true
64
+ end
65
+
66
+ def delete_entry(key, options)
67
+ @stores.map do |store|
68
+ store.send(:delete_entry, key, options)
69
+ end.include? true
70
+ end
71
+
72
+ private
73
+ def initialize_store(arg)
74
+ parameters = arg
75
+ *parameters = *[arg.keys.first, arg.values].flatten if arg.is_a?(Hash)
76
+
77
+ stores << ActiveSupport::Cache.lookup_store(parameters)
78
+ end
79
+
80
+ end
81
+ end
data/lib/layercake.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Layercake
2
+ autoload :Store, 'layercake/store'
3
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'layercake'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestLayercake < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: layercake
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Peter Haza
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-08 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: |-
36
+ LayerCake is a simple gem that allows you to specify more than one cache store in rails.
37
+ It is built on the idea that memory store is the most efficient store with no network or file overhead, but serves multi-process or multi-server architectures, hence a fallback like filestore or memcached store is necessary.
38
+ email: peter.haza@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.markdown
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.markdown
51
+ - Rakefile
52
+ - VERSION
53
+ - layercake.gemspec
54
+ - lib/layercake.rb
55
+ - lib/layercake/store.rb
56
+ - test/helper.rb
57
+ - test/test_layercake.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/phaza/layercake
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Support for multiple cache stores in rails, typically memory and/or file and memcached
92
+ test_files:
93
+ - test/helper.rb
94
+ - test/test_layercake.rb