mongo_rails_cache 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1 @@
1
+ require 'store/cache'
@@ -0,0 +1,50 @@
1
+ begin
2
+ require 'mongo'
3
+ rescue LoadError => e
4
+ $stderr.puts "You don't have mongo installed in your application. Please add it to your Gemfile and run bundle install"
5
+ raise e
6
+ end
7
+
8
+ require 'active_support/all'
9
+
10
+ module Mongo
11
+ module Store
12
+ class Cache < ActiveSupport::Cache::Store
13
+ attr_reader :collection, :options
14
+
15
+ def initialize(collection, options={})
16
+ @collection, @options = collection, options || {}
17
+ end
18
+
19
+ def expires_in
20
+ @expires_in ||= options[:expires_in] || 1.month
21
+ end
22
+
23
+ def write_entry(key, entry, options)
24
+ doc = {:_id => key.to_s, :value => BSON::Binary.new(Marshal.dump(entry))}
25
+ @collection.save(doc)
26
+ true
27
+ end
28
+
29
+ def read_entry(key, options)
30
+ entry = @collection.find_one(:_id => key.to_s)
31
+ if entry
32
+ Marshal.load(entry['value'].to_s)
33
+ else
34
+ nil
35
+ end
36
+ end
37
+
38
+ # we don't get any info from mongo driver if delete actually deleted anything. this will always return true.
39
+ def delete_entry(key, options)
40
+ @collection.remove({:_id => key.to_s})
41
+ true
42
+ end
43
+
44
+ def clear(options=nil)
45
+ @collection.remove
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_rails_cache}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ashley Streb"]
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
- "lib/mongo_store.rb",
28
- "lib/mongo_store/cache.rb",
27
+ "lib/mongo_rails_cache.rb",
28
+ "lib/store/cache.rb",
29
29
  "mongo_rails_cache.gemspec",
30
30
  "spec/cache/cache_spec.rb",
31
- "spec/mongo_store_spec.rb",
31
+ "spec/mongo_rails_cache_spec.rb",
32
32
  "spec/spec_helper.rb"
33
33
  ]
34
34
  s.homepage = %q{http://github.com/roark31337/mongo_rails_cache}
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.summary = %q{Rails3 ActiveSupport Cache built on MongoDB}
39
39
  s.test_files = [
40
40
  "spec/cache/cache_spec.rb",
41
- "spec/mongo_store_spec.rb",
41
+ "spec/mongo_rails_cache_spec.rb",
42
42
  "spec/spec_helper.rb"
43
43
  ]
44
44
 
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe MongoStore::Cache do
3
+ describe Mongo::Store::Cache do
4
4
  before(:each) do
5
5
  DB.collections.each do |collection|
6
6
  collection.remove
@@ -8,11 +8,11 @@ describe MongoStore::Cache do
8
8
  end
9
9
 
10
10
  @collection = DB['mongo_store_cache']
11
- @store = MongoStore::Cache.new(@collection)
11
+ @store = Mongo::Store::Cache.new(@collection)
12
12
  end
13
13
 
14
14
  let(:collection) { DB['mongo_store_cache'] }
15
- let(:store) { MongoStore::Cache.new(collection, nil) }
15
+ let(:store) { Mongo::Store::Cache.new(collection, nil) }
16
16
 
17
17
  it "has a collection" do
18
18
  store.collection.should == collection
@@ -23,7 +23,7 @@ describe MongoStore::Cache do
23
23
  end
24
24
 
25
25
  it "can set default expires_in" do
26
- MongoStore::Cache.new(collection, :expires_in => 5.minutes).expires_in.should == 5.minutes
26
+ Mongo::Store::Cache.new(collection, :expires_in => 5.minutes).expires_in.should == 5.minutes
27
27
  end
28
28
 
29
29
  describe "#write" do
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mongo::Store::Cache do
4
+
5
+ it "should load Mongo::Store::Cache" do
6
+ lambda {Mongo::Store::Cache}.should_not raise_error
7
+ end
8
+ end
@@ -2,7 +2,7 @@ gem 'activesupport'
2
2
  $:.unshift(File.expand_path('../../lib', __FILE__))
3
3
 
4
4
  require 'rubygems'
5
- require 'mongo_store'
5
+ require 'mongo_rails_cache'
6
6
  require 'mongo'
7
7
 
8
8
  require 'rspec'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ashley Streb
@@ -49,11 +49,11 @@ files:
49
49
  - README.rdoc
50
50
  - Rakefile
51
51
  - VERSION
52
- - lib/mongo_store.rb
53
- - lib/mongo_store/cache.rb
52
+ - lib/mongo_rails_cache.rb
53
+ - lib/store/cache.rb
54
54
  - mongo_rails_cache.gemspec
55
55
  - spec/cache/cache_spec.rb
56
- - spec/mongo_store_spec.rb
56
+ - spec/mongo_rails_cache_spec.rb
57
57
  - spec/spec_helper.rb
58
58
  has_rdoc: true
59
59
  homepage: http://github.com/roark31337/mongo_rails_cache
@@ -89,5 +89,5 @@ specification_version: 3
89
89
  summary: Rails3 ActiveSupport Cache built on MongoDB
90
90
  test_files:
91
91
  - spec/cache/cache_spec.rb
92
- - spec/mongo_store_spec.rb
92
+ - spec/mongo_rails_cache_spec.rb
93
93
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- require 'mongo_store/cache'
@@ -1,48 +0,0 @@
1
- begin
2
- require 'mongo'
3
- rescue LoadError => e
4
- $stderr.puts "You don't have mongo installed in your application. Please add it to your Gemfile and run bundle install"
5
- raise e
6
- end
7
-
8
- require 'active_support/all'
9
-
10
- module MongoStore
11
- class Cache < ActiveSupport::Cache::Store
12
- attr_reader :collection, :options
13
-
14
- def initialize(collection, options={})
15
- @collection, @options = collection, options || {}
16
- end
17
-
18
- def expires_in
19
- @expires_in ||= options[:expires_in] || 1.month
20
- end
21
-
22
- def write_entry(key, entry, options)
23
- doc = {:_id => key.to_s, :value => BSON::Binary.new(Marshal.dump(entry))}
24
- @collection.save(doc)
25
- true
26
- end
27
-
28
- def read_entry(key, options)
29
- entry = @collection.find_one(:_id => key.to_s)
30
- if entry
31
- Marshal.load(entry['value'].to_s)
32
- else
33
- nil
34
- end
35
- end
36
-
37
- # we don't get any info from mongo driver if delete actually deleted anything. this will always return true.
38
- def delete_entry(key, options)
39
- @collection.remove({:_id => key.to_s})
40
- true
41
- end
42
-
43
- def clear(options=nil)
44
- @collection.remove
45
- end
46
-
47
- end
48
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe MongoStore do
4
-
5
- it "should load MongoStore::Cache" do
6
- lambda {MongoStore::Cache}.should_not raise_error
7
- end
8
- end