cachetastic 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gem 'memcache-client'
7
7
  gem 'rspec'
8
8
  gem 'timecop'
9
9
  gem 'redis'
10
- gem 'dalli'
10
+ gem 'dalli'
11
+ gem 'mongoid'
@@ -1,23 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cachetastic (3.6.0)
4
+ cachetastic (3.7.0)
5
5
  activesupport
6
6
  configatron
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activemodel (3.2.11)
12
+ activesupport (= 3.2.11)
13
+ builder (~> 3.0.0)
11
14
  activesupport (3.2.11)
12
15
  i18n (~> 0.6)
13
16
  multi_json (~> 1.0)
17
+ builder (3.0.4)
14
18
  configatron (2.9.1)
15
19
  yamler (>= 0.1.0)
16
20
  dalli (2.6.0)
17
21
  diff-lcs (1.1.3)
18
22
  i18n (0.6.1)
19
23
  memcache-client (1.8.5)
24
+ mongoid (3.0.9)
25
+ activemodel (~> 3.1)
26
+ moped (~> 1.1)
27
+ origin (~> 1.0)
28
+ tzinfo (~> 0.3.22)
29
+ moped (1.3.2)
20
30
  multi_json (1.5.0)
31
+ origin (1.0.11)
21
32
  rake (10.0.3)
22
33
  redis (3.0.2)
23
34
  rspec (2.12.0)
@@ -29,6 +40,7 @@ GEM
29
40
  diff-lcs (~> 1.1.3)
30
41
  rspec-mocks (2.12.1)
31
42
  timecop (0.5.7)
43
+ tzinfo (0.3.35)
32
44
  yamler (0.1.0)
33
45
 
34
46
  PLATFORMS
@@ -38,6 +50,7 @@ DEPENDENCIES
38
50
  cachetastic!
39
51
  dalli
40
52
  memcache-client
53
+ mongoid
41
54
  rake
42
55
  redis
43
56
  rspec
@@ -4,6 +4,11 @@ require 'active_support/core_ext'
4
4
  require 'fileutils'
5
5
  require 'singleton'
6
6
  require 'uri'
7
+ begin
8
+ require 'mongoid'
9
+ rescue Exception => e
10
+ puts "Mongoid 3 support is unavailable. To use Mongoid 3 do `gem install mongoid`"
11
+ end
7
12
  begin
8
13
  require 'memcache'
9
14
  rescue Exception => e
@@ -0,0 +1,73 @@
1
+ module Cachetastic
2
+ module Adapters
3
+ class Mongoid < Cachetastic::Adapters::Base
4
+
5
+ class Store
6
+ include ::Mongoid::Document
7
+ include ::Mongoid::Timestamps
8
+
9
+ field :cache_class, type: String
10
+ field :key, type: String
11
+ field :value, type: Object
12
+ field :expiry_time, type: DateTime
13
+
14
+ index({cache_class: 1, key: 1}, {background: true})
15
+
16
+ validates :cache_class, presence: true
17
+ validates :key, presence: true, uniqueness: {scope: :cache_class}
18
+ validates :value, presence: {allow_blank: true}
19
+ validates :expiry_time, presence: true
20
+ end
21
+
22
+ attr_accessor :klass
23
+
24
+ def initialize(klass)
25
+ self.klass = klass
26
+ super
27
+ end
28
+
29
+ def get(key) # :nodoc:
30
+ obj = connection.where(key: key).first
31
+ if obj
32
+ if obj.expiry_time > Time.now
33
+ return obj.value
34
+ else
35
+ obj.destroy
36
+ end
37
+ end
38
+ return nil
39
+ end # get
40
+
41
+ def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
42
+ Cachetastic::Adapters::Mongoid::Store.create!(cache_class: self.klass.name, key: key, value: value, expiry_time: expiry_time.from_now)
43
+ return value
44
+ end # set
45
+
46
+ def delete(key) # :nodoc:
47
+ obj = connection.where(key: key).first
48
+ if obj
49
+ obj.destroy
50
+ end
51
+ return nil
52
+ end # delete
53
+
54
+ def expire_all # :nodoc:
55
+ connection.destroy_all
56
+ return nil
57
+ end # expire_all
58
+
59
+ def transform_key(key) # :nodoc:
60
+ key.to_s.hexdigest
61
+ end
62
+
63
+ private
64
+ def connection
65
+ @connection ||= begin
66
+ Cachetastic::Adapters::Mongoid::Store.create_indexes
67
+ Cachetastic::Adapters::Mongoid::Store.where(cache_class: self.klass.name)
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Cachetastic
2
- VERSION = "3.6.0"
2
+ VERSION = "3.7.0"
3
3
  end
@@ -89,7 +89,7 @@ describe Cachetastic::Adapters do
89
89
 
90
90
  end
91
91
 
92
- ['LocalMemory', 'File', 'Memcached', 'Redis', 'Dalli'].each do |adapter|
92
+ ['LocalMemory', 'File', 'Memcached', 'Redis', 'Dalli', 'Mongoid'].each do |adapter|
93
93
 
94
94
  describe "#{adapter} (Common)" do
95
95
 
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cachetastic::Adapters::Mongoid do
4
+ end
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: cachetastic_test
5
+ hosts:
6
+ - localhost:27017
@@ -2,7 +2,12 @@ ENV["RACK_ENV"] ||= "test"
2
2
 
3
3
  require 'bundler/setup'
4
4
 
5
+ require 'mongoid'
6
+ Mongoid.load!(File.join(File.dirname(__FILE__), "config.yml"), :test)
7
+
5
8
  require 'cachetastic' # and any other gems you need
9
+
10
+
6
11
  require 'timecop'
7
12
 
8
13
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -79,6 +79,7 @@ files:
79
79
  - lib/cachetastic/adapters/file.rb
80
80
  - lib/cachetastic/adapters/local_memory.rb
81
81
  - lib/cachetastic/adapters/memcached.rb
82
+ - lib/cachetastic/adapters/mongoid.rb
82
83
  - lib/cachetastic/adapters/redis.rb
83
84
  - lib/cachetastic/cache.rb
84
85
  - lib/cachetastic/cacheable.rb
@@ -90,11 +91,13 @@ files:
90
91
  - spec/cachetastic/adapters/file_spec.rb
91
92
  - spec/cachetastic/adapters/local_memory_spec.rb
92
93
  - spec/cachetastic/adapters/memcached_spec.rb
94
+ - spec/cachetastic/adapters/mongoid_spec.rb
93
95
  - spec/cachetastic/adapters/redis_spec.rb
94
96
  - spec/cachetastic/cache_spec.rb
95
97
  - spec/cachetastic/cacheable_spec.rb
96
98
  - spec/cachetastic/logger_spec.rb
97
99
  - spec/cachetastic/store_object_spec.rb
100
+ - spec/config.yml
98
101
  - spec/spec_helper.rb
99
102
  homepage: ''
100
103
  licenses:
@@ -126,9 +129,11 @@ test_files:
126
129
  - spec/cachetastic/adapters/file_spec.rb
127
130
  - spec/cachetastic/adapters/local_memory_spec.rb
128
131
  - spec/cachetastic/adapters/memcached_spec.rb
132
+ - spec/cachetastic/adapters/mongoid_spec.rb
129
133
  - spec/cachetastic/adapters/redis_spec.rb
130
134
  - spec/cachetastic/cache_spec.rb
131
135
  - spec/cachetastic/cacheable_spec.rb
132
136
  - spec/cachetastic/logger_spec.rb
133
137
  - spec/cachetastic/store_object_spec.rb
138
+ - spec/config.yml
134
139
  - spec/spec_helper.rb