cachy 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ script: "bundle exec rake"
2
+ rvm:
3
+ - ree
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,9 +1,7 @@
1
1
  source :rubygems
2
-
3
- gem 'mini_memory_store'
2
+ gemspec
4
3
 
5
4
  group :development do
6
5
  gem 'rake'
7
6
  gem 'rspec', '~>2'
8
- gem 'jeweler'
9
7
  end
@@ -1,28 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cachy (0.3.0)
5
+ mini_memory_store
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.2)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
+ diff-lcs (1.1.3)
10
11
  mini_memory_store (0.1.0)
11
- rake (0.8.7)
12
- rspec (2.3.0)
13
- rspec-core (~> 2.3.0)
14
- rspec-expectations (~> 2.3.0)
15
- rspec-mocks (~> 2.3.0)
16
- rspec-core (2.3.1)
17
- rspec-expectations (2.3.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.3.0)
12
+ rake (0.9.2.2)
13
+ rspec (2.9.0)
14
+ rspec-core (~> 2.9.0)
15
+ rspec-expectations (~> 2.9.0)
16
+ rspec-mocks (~> 2.9.0)
17
+ rspec-core (2.9.0)
18
+ rspec-expectations (2.9.0)
19
+ diff-lcs (~> 1.1.3)
20
+ rspec-mocks (2.9.0)
20
21
 
21
22
  PLATFORMS
22
23
  ruby
23
24
 
24
25
  DEPENDENCIES
25
- jeweler
26
- mini_memory_store
26
+ cachy!
27
27
  rake
28
28
  rspec (~> 2)
data/Rakefile CHANGED
@@ -1,21 +1,22 @@
1
- task :default => :spec
2
- require "rspec/core/rake_task"
3
- RSpec::Core::RakeTask.new(:spec) do |t|
4
- t.rspec_opts = '--backtrace --color'
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default do
4
+ sh "rspec spec/"
5
5
  end
6
6
 
7
- begin
8
- require 'jeweler'
9
- project_name = 'cachy'
10
- Jeweler::Tasks.new do |gem|
11
- gem.name = project_name
12
- gem.summary = "Caching library for projects that have many processes or many caches"
13
- gem.email = "grosser.michael@gmail.com"
14
- gem.homepage = "http://github.com/grosser/#{project_name}"
15
- gem.authors = ["Michael Grosser"]
16
- end
7
+ # extracted from https://github.com/grosser/project_template
8
+ rule /^version:bump:.*/ do |t|
9
+ sh "git status | grep 'nothing to commit'" # ensure we are not dirty
10
+ index = ['major', 'minor','patch'].index(t.name.split(':').last)
11
+ file = 'lib/cachy/version.rb'
12
+
13
+ version_file = File.read(file)
14
+ old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
15
+ version_parts[index] = version_parts[index].to_i + 1
16
+ version_parts[2] = 0 if index < 2 # remove patch for minor
17
+ version_parts[1] = 0 if index < 1 # remove minor for major
18
+ new_version = version_parts * '.'
19
+ File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
17
20
 
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
21
+ sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
21
22
  end
data/Readme.md CHANGED
@@ -47,7 +47,7 @@ Expire all all caches of one kind when code inside the cache has been updated
47
47
  Cachy.cache(:a_key, :witout_locale=>true){ 'German' } == 'English'
48
48
 
49
49
  ####Caching results of other caches
50
- When inner cache is expired outer cache would normally still shows old results.
50
+ When inner cache is expired outer cache would normally still shows old results.<br/>
51
51
  --> expire outer cache when inner cache is expired.
52
52
 
53
53
  a = Cachy.cache(:a, :expires_in=>1.day){ expensive() }
@@ -62,7 +62,7 @@ In case they get to long for your caching backend, makes them short but unreadab
62
62
  Cachy.cache(:a_key, :hash_key=>true){ expensive } # per call
63
63
 
64
64
  #### Uses .cache_key when available
65
- E.g. ActiveRecord objects are stored in the key with their updated_at timestamp.
65
+ E.g. ActiveRecord objects are stored in the key with their updated_at timestamp.<br/>
66
66
  When they are updated the cache is automatically expired.
67
67
 
68
68
  Cachy.cache(:my_key, User.first){ expensive }
@@ -96,7 +96,7 @@ Use to cache e.g. Erb output
96
96
  <% end %>
97
97
 
98
98
  ###Cachy.cache_store
99
- No ActionController::Base.cache_store ?
99
+ No ActionController::Base.cache_store ?<br/>
100
100
  Give me something that responds to read/write(Rails style) or []/store([Moneta](http://github.com/wycats/moneta/tree/master)) or get/set(Memcached)
101
101
  Cachy.cache_store = some_cache
102
102
 
@@ -117,6 +117,8 @@ Authors
117
117
  ###Contributors
118
118
  - [mindreframer](http://www.simplewebapp.de/roman)
119
119
 
120
- [Michael Grosser](http://grosser.it)
121
- grosser.michael@gmail.com
122
- Hereby placed under public domain, do what you want, just do not hold me accountable...
120
+ [Michael Grosser](http://grosser.it)<br/>
121
+ michael@grosser.it<br/>
122
+ License: MIT<br/>
123
+ [![Build Status](https://secure.travis-ci.org/grosser/cachy.png)](http://travis-ci.org/grosser/cachy)
124
+
@@ -1,72 +1,13 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ name = "cachy"
3
+ require "#{name}/version"
5
4
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{cachy}
8
- s.version = "0.2.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ Gem::Specification.new name, Cachy::VERSION do |s|
6
+ s.summary = "Caching library for projects that have many processes or many caches"
11
7
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2011-06-17}
13
- s.email = %q{grosser.michael@gmail.com}
14
- s.files = [
15
- "Gemfile",
16
- "Gemfile.lock",
17
- "Rakefile",
18
- "Readme.md",
19
- "VERSION",
20
- "cachy.gemspec",
21
- "lib/cachy.rb",
22
- "lib/cachy/memcache_timeout_protection.rb",
23
- "lib/cachy/memcached_wrapper.rb",
24
- "lib/cachy/moneta_wrapper.rb",
25
- "lib/cachy/redis_wrapper.rb",
26
- "lib/cachy/wrapper.rb",
27
- "spec/cachy/memcache_timeout_protection_spec.rb",
28
- "spec/cachy/memcached_wrapper_spec.rb",
29
- "spec/cachy/moneta_wrapper_spec.rb",
30
- "spec/cachy/redis_wrapper_spec.rb",
31
- "spec/cachy_spec.rb",
32
- "spec/mem_cache.rb",
33
- "spec/spec_helper.rb",
34
- "spec/test_cache.rb"
35
- ]
36
- s.homepage = %q{http://github.com/grosser/cachy}
37
- s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.6.2}
39
- s.summary = %q{Caching library for projects that have many processes or many caches}
40
- s.test_files = [
41
- "spec/cachy/memcache_timeout_protection_spec.rb",
42
- "spec/cachy/memcached_wrapper_spec.rb",
43
- "spec/cachy/moneta_wrapper_spec.rb",
44
- "spec/cachy/redis_wrapper_spec.rb",
45
- "spec/cachy_spec.rb",
46
- "spec/mem_cache.rb",
47
- "spec/spec_helper.rb",
48
- "spec/test_cache.rb"
49
- ]
50
-
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<mini_memory_store>, [">= 0"])
56
- s.add_development_dependency(%q<rake>, [">= 0"])
57
- s.add_development_dependency(%q<rspec>, ["~> 2"])
58
- s.add_development_dependency(%q<jeweler>, [">= 0"])
59
- else
60
- s.add_dependency(%q<mini_memory_store>, [">= 0"])
61
- s.add_dependency(%q<rake>, [">= 0"])
62
- s.add_dependency(%q<rspec>, ["~> 2"])
63
- s.add_dependency(%q<jeweler>, [">= 0"])
64
- end
65
- else
66
- s.add_dependency(%q<mini_memory_store>, [">= 0"])
67
- s.add_dependency(%q<rake>, [">= 0"])
68
- s.add_dependency(%q<rspec>, ["~> 2"])
69
- s.add_dependency(%q<jeweler>, [">= 0"])
70
- end
8
+ s.email = "michael@grosser.it"
9
+ s.homepage = "http://github.com/grosser/#{name}"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.license = "MIT"
12
+ s.add_runtime_dependency "mini_memory_store"
71
13
  end
72
-
@@ -1,6 +1,6 @@
1
1
  require 'mini_memory_store'
2
2
 
3
- class Cachy
3
+ module Cachy
4
4
  WHILE_RUNNING_TIMEOUT = 5*60 #seconds
5
5
  KEY_VERSION_TIMEOUT = 30 #seconds
6
6
  HEALTH_CHECK_KEY = 'cachy_healthy'
@@ -29,7 +29,7 @@ class Cachy
29
29
  cache_store.write key, result, options
30
30
  result
31
31
  end
32
-
32
+
33
33
  def self.cache_if(cond, *args, &block)
34
34
  if cond
35
35
  cache(*args, &block)
@@ -118,6 +118,8 @@ class Cachy
118
118
  def self.cache_store=(cache)
119
119
  @cache_store = wrap_cache(cache)
120
120
  @cache_store.write HEALTH_CHECK_KEY, 'yes'
121
+ @key_versions_cache_store = nil
122
+ memory_store.clear
121
123
  end
122
124
 
123
125
  def self.cache_store
@@ -0,0 +1,3 @@
1
+ module Cachy
2
+ Version = VERSION = '0.3.0'
3
+ end
@@ -1,5 +1,5 @@
1
- require 'spec/spec_helper'
2
- require 'spec/mem_cache'
1
+ require 'spec_helper'
2
+ require './spec/mem_cache'
3
3
  require 'cachy/memcache_timeout_protection'
4
4
 
5
5
  describe "MemCache timeout protection" do
@@ -18,14 +18,14 @@ describe "MemCache timeout protection" do
18
18
  end
19
19
 
20
20
  it "catches timeout errors" do
21
- MemCache.read_error_callback = lambda{}
21
+ MemCache.read_error_callback = lambda{|x|}
22
22
  simulate_timeout
23
23
  cache.get('x').should == nil
24
24
  cache.read_error_occurred.should == true
25
25
  end
26
26
 
27
27
  it "resets error_occurred to false after successful get" do
28
- MemCache.read_error_callback = lambda{}
28
+ MemCache.read_error_callback = lambda{|x|}
29
29
  simulate_timeout
30
30
  cache.get('x').should == nil
31
31
  cache.stub!(:stubable_cache_get).and_return 1
@@ -42,9 +42,9 @@ describe "MemCache timeout protection" do
42
42
  end
43
43
 
44
44
  it "calls the callback" do
45
- MemCache.read_error_callback = lambda{ 1 }
45
+ MemCache.read_error_callback = lambda{|x| 1 }
46
46
  simulate_timeout
47
47
  cache.get('x').should == 1
48
48
  cache.read_error_occurred.should == true
49
49
  end
50
- end
50
+ end
@@ -1,5 +1,5 @@
1
- require 'spec/spec_helper'
2
- require 'spec/mem_cache'
1
+ require 'spec_helper'
2
+ require './spec/mem_cache'
3
3
 
4
4
  describe "Cachy::MemcachedWrapper" do
5
5
  before :all do
@@ -34,4 +34,4 @@ describe "Cachy::MemcachedWrapper" do
34
34
  @cache.should_receive(:delete).with('x_v1')
35
35
  Cachy.expire(:x)
36
36
  end
37
- end
37
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  class TestMoneta
4
4
  def initialize
@@ -56,4 +56,4 @@ describe "Cachy::MonetaWrapper" do
56
56
  @cache.should_receive(:delete).with('x_v1')
57
57
  Cachy.expire(:x)
58
58
  end
59
- end
59
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  class TestRedis
4
4
  def self.to_s
@@ -30,6 +30,8 @@ class TestRedis
30
30
  end
31
31
 
32
32
  describe "Cachy::RedisWrapper" do
33
+ let(:yaml_ending) { RUBY_VERSION > '1.9' ? "\n...\n" : "\n" }
34
+
33
35
  before :all do
34
36
  @cache = TestRedis.new
35
37
  Cachy.cache_store = @cache
@@ -49,13 +51,13 @@ describe "Cachy::RedisWrapper" do
49
51
  end
50
52
 
51
53
  it "can cache without expires" do
52
- @cache.should_receive(:set).with('x_v1', "--- SUCCESS\n")
54
+ @cache.should_receive(:set).with('x_v1', "--- SUCCESS#{yaml_ending}")
53
55
  @cache.should_not_receive(:expire)
54
56
  Cachy.cache(:x){ 'SUCCESS' }.should == 'SUCCESS'
55
57
  end
56
58
 
57
59
  it "can cache with expires" do
58
- @cache.should_receive(:set).with('x_v1', "--- SUCCESS\n")
60
+ @cache.should_receive(:set).with('x_v1', "--- SUCCESS#{yaml_ending}")
59
61
  @cache.should_receive(:expire).with('x_v1', 1)
60
62
  Cachy.cache(:x, :expires_in=>1){ 'SUCCESS' }.should == 'SUCCESS'
61
63
  end
@@ -64,4 +66,4 @@ describe "Cachy::RedisWrapper" do
64
66
  @cache.should_receive(:del).with('x_v1')
65
67
  Cachy.expire(:x)
66
68
  end
67
- end
69
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Cachy do
4
4
  before do
@@ -49,7 +49,7 @@ describe Cachy do
49
49
  Cachy.cache(:x){ true }.should == true
50
50
  end
51
51
  end
52
-
52
+
53
53
  describe :cache_if do
54
54
  it "should not call the cache command if condition is wrong" do
55
55
  Cachy.should_not_receive(:cache)
@@ -57,14 +57,14 @@ describe Cachy do
57
57
  "asd"
58
58
  end
59
59
  end
60
-
60
+
61
61
  it "should call cache command if condition is true" do
62
62
  Cachy.should_receive(:cache)
63
63
  Cachy.cache_if(true, :x) do
64
64
  "asd"
65
65
  end
66
66
  end
67
-
67
+
68
68
  it "should pass params correctly" do
69
69
  Cachy.should_receive(:cache).with(:x, {:y => 1}, :expires_in => 3)
70
70
  Cachy.cache_if(true, :x, {:y => 1}, :expires_in => 3) do
@@ -357,6 +357,14 @@ describe Cachy do
357
357
  Cachy.increment_key :x
358
358
  Cachy.key_versions.should == {:x => 2}
359
359
  end
360
+
361
+ it "invalidates the cached key_versions_cache_store when a new cache store is used" do
362
+ key_cache.write(Cachy::KEY_VERSIONS_KEY, :x => 1)
363
+ Cachy.key_versions_cache_store = key_cache
364
+ Cachy.key_versions.should == {:x => 1}
365
+ Cachy.cache_store = @cache
366
+ Cachy.key_versions.should == {}
367
+ end
360
368
  end
361
369
 
362
370
  describe :delete_key do
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
- require 'spec/test_cache'
1
+ require './spec/test_cache'
3
2
  $LOAD_PATH << 'lib'
4
- require 'cachy'
3
+ require 'cachy'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-17 00:00:00 +02:00
19
- default_executable:
18
+ date: 2012-03-29 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
@@ -31,51 +31,8 @@ dependencies:
31
31
  type: :runtime
32
32
  name: mini_memory_store
33
33
  version_requirements: *id001
34
- prerelease: false
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
45
- type: :development
46
- name: rake
47
- version_requirements: *id002
48
- prerelease: false
49
- - !ruby/object:Gem::Dependency
50
- requirement: &id003 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ~>
54
- - !ruby/object:Gem::Version
55
- hash: 7
56
- segments:
57
- - 2
58
- version: "2"
59
- type: :development
60
- name: rspec
61
- version_requirements: *id003
62
- prerelease: false
63
- - !ruby/object:Gem::Dependency
64
- requirement: &id004 !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
- type: :development
74
- name: jeweler
75
- version_requirements: *id004
76
- prerelease: false
77
34
  description:
78
- email: grosser.michael@gmail.com
35
+ email: michael@grosser.it
79
36
  executables: []
80
37
 
81
38
  extensions: []
@@ -83,17 +40,18 @@ extensions: []
83
40
  extra_rdoc_files: []
84
41
 
85
42
  files:
43
+ - .travis.yml
86
44
  - Gemfile
87
45
  - Gemfile.lock
88
46
  - Rakefile
89
47
  - Readme.md
90
- - VERSION
91
48
  - cachy.gemspec
92
49
  - lib/cachy.rb
93
50
  - lib/cachy/memcache_timeout_protection.rb
94
51
  - lib/cachy/memcached_wrapper.rb
95
52
  - lib/cachy/moneta_wrapper.rb
96
53
  - lib/cachy/redis_wrapper.rb
54
+ - lib/cachy/version.rb
97
55
  - lib/cachy/wrapper.rb
98
56
  - spec/cachy/memcache_timeout_protection_spec.rb
99
57
  - spec/cachy/memcached_wrapper_spec.rb
@@ -103,10 +61,9 @@ files:
103
61
  - spec/mem_cache.rb
104
62
  - spec/spec_helper.rb
105
63
  - spec/test_cache.rb
106
- has_rdoc: true
107
64
  homepage: http://github.com/grosser/cachy
108
- licenses: []
109
-
65
+ licenses:
66
+ - MIT
110
67
  post_install_message:
111
68
  rdoc_options: []
112
69
 
@@ -133,16 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
90
  requirements: []
134
91
 
135
92
  rubyforge_project:
136
- rubygems_version: 1.6.2
93
+ rubygems_version: 1.8.15
137
94
  signing_key:
138
95
  specification_version: 3
139
96
  summary: Caching library for projects that have many processes or many caches
140
- test_files:
141
- - spec/cachy/memcache_timeout_protection_spec.rb
142
- - spec/cachy/memcached_wrapper_spec.rb
143
- - spec/cachy/moneta_wrapper_spec.rb
144
- - spec/cachy/redis_wrapper_spec.rb
145
- - spec/cachy_spec.rb
146
- - spec/mem_cache.rb
147
- - spec/spec_helper.rb
148
- - spec/test_cache.rb
97
+ test_files: []
98
+
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.1