cachetastic 3.2.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/README.md +3 -2
- data/lib/cachetastic/adapters/memcached.rb +11 -5
- data/lib/cachetastic/adapters/redis.rb +56 -0
- data/lib/cachetastic/store_object.rb +4 -0
- data/lib/cachetastic/version.rb +1 -1
- data/lib/cachetastic.rb +7 -0
- data/spec/cachetastic/adapters/base_spec.rb +1 -1
- metadata +3 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cachetastic (3.
|
4
|
+
cachetastic (3.5.0)
|
5
5
|
activesupport
|
6
6
|
configatron
|
7
7
|
|
@@ -18,6 +18,7 @@ GEM
|
|
18
18
|
memcache-client (1.8.5)
|
19
19
|
multi_json (1.5.0)
|
20
20
|
rake (10.0.3)
|
21
|
+
redis (3.0.2)
|
21
22
|
rspec (2.12.0)
|
22
23
|
rspec-core (~> 2.12.0)
|
23
24
|
rspec-expectations (~> 2.12.0)
|
@@ -36,5 +37,6 @@ DEPENDENCIES
|
|
36
37
|
cachetastic!
|
37
38
|
memcache-client
|
38
39
|
rake
|
40
|
+
redis
|
39
41
|
rspec
|
40
42
|
timecop
|
data/README.md
CHANGED
@@ -22,9 +22,10 @@ configatron.cachetastic.defaults.debug = false
|
|
22
22
|
configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
|
23
23
|
configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::File
|
24
24
|
configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::Memcached
|
25
|
+
configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::Redis
|
25
26
|
|
26
27
|
# This will marshall objects into and out of the store.
|
27
|
-
# The default is :none, except for Cachetastic::Adapters::File, which
|
28
|
+
# The default is :none, except for Cachetastic::Adapters::File and Cachetastic::Adapters::Redis, which default to :yaml
|
28
29
|
configatron.cachetastic.defaults.marshall_method = :none
|
29
30
|
configatron.cachetastic.defaults.marshall_method = :yaml
|
30
31
|
configatron.cachetastic.defaults.marshall_method = :ruby
|
@@ -32,7 +33,7 @@ configatron.cachetastic.defaults.marshall_method = :ruby
|
|
32
33
|
# This sets how long objects will live in the cache before they are auto expired.
|
33
34
|
configatron.cachetastic.defaults.default_expiry = 86400 # time in seconds (default: 24 hours)
|
34
35
|
|
35
|
-
# When
|
36
|
+
# When saving objects into the cache the expiry_swing is +/- to the expiry time.
|
36
37
|
# Example: if the expiry time is 1 minute, and the swing is 15 seconds,
|
37
38
|
# objects will go into the cache with an expiry time sometime between 45 seconds and 75 seconds.
|
38
39
|
# The default is 0 seconds.
|
@@ -27,6 +27,10 @@ module Cachetastic # :nodoc:
|
|
27
27
|
# See <tt>Cachetastic::Adapters::Base</tt> for a list of public API
|
28
28
|
# methods.
|
29
29
|
class Memcached < Cachetastic::Adapters::Base
|
30
|
+
|
31
|
+
attr_accessor :servers
|
32
|
+
attr_accessor :mc_options
|
33
|
+
attr_accessor :delete_delay
|
30
34
|
|
31
35
|
def initialize(klass) # :nodoc:
|
32
36
|
define_accessor(:servers)
|
@@ -34,11 +38,13 @@ module Cachetastic # :nodoc:
|
|
34
38
|
define_accessor(:delete_delay)
|
35
39
|
self.delete_delay = 0
|
36
40
|
self.servers = ['127.0.0.1:11211']
|
37
|
-
self.mc_options = {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
self.mc_options = {
|
42
|
+
c_threshold: 10_000,
|
43
|
+
compression: true,
|
44
|
+
debug: false,
|
45
|
+
readonly: false,
|
46
|
+
urlencode: false
|
47
|
+
}
|
42
48
|
super
|
43
49
|
connection
|
44
50
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Cachetastic
|
2
|
+
module Adapters
|
3
|
+
class Redis < Cachetastic::Adapters::Base
|
4
|
+
|
5
|
+
def initialize(klass)
|
6
|
+
define_accessor(:redis_host)
|
7
|
+
define_accessor(:redis_options)
|
8
|
+
define_accessor(:delete_delay)
|
9
|
+
self.redis_host ||= "redis://localhost:6379/"
|
10
|
+
self.redis_options = ::Redis::Client::DEFAULTS.merge({
|
11
|
+
db: "cachetastic",
|
12
|
+
url: self.redis_host
|
13
|
+
})
|
14
|
+
super(klass)
|
15
|
+
self.marshal_method = :yaml if self.marshal_method == :none
|
16
|
+
connection
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(key) # :nodoc:
|
20
|
+
connection.get(transform_key(key))
|
21
|
+
end # get
|
22
|
+
|
23
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
|
24
|
+
so = Cachetastic::Cache::StoreObject.new(key, value, expiry_time.from_now)
|
25
|
+
connection.set(transform_key(key), marshal(so))
|
26
|
+
return value
|
27
|
+
end # set
|
28
|
+
|
29
|
+
def delete(key) # :nodoc:
|
30
|
+
connection.del(transform_key(key))
|
31
|
+
end # delete
|
32
|
+
|
33
|
+
def expire_all # :nodoc:
|
34
|
+
connection.flushdb
|
35
|
+
return nil
|
36
|
+
end # expire_all
|
37
|
+
|
38
|
+
def transform_key(key) # :nodoc:
|
39
|
+
key.to_s.hexdigest
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid?
|
43
|
+
!connection.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def connection
|
48
|
+
if @connection.nil?
|
49
|
+
@connection = ::Redis.new(self.redis_options)
|
50
|
+
end
|
51
|
+
return @connection
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/cachetastic/version.rb
CHANGED
data/lib/cachetastic.rb
CHANGED
@@ -3,9 +3,16 @@ require 'logger'
|
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'singleton'
|
6
|
+
require 'uri'
|
6
7
|
begin
|
7
8
|
require 'memcache'
|
8
9
|
rescue Exception => e
|
10
|
+
puts "Memcached support is unavailable. To use Memcached do `gem install memcache-client`"
|
11
|
+
end
|
12
|
+
begin
|
13
|
+
require 'redis'
|
14
|
+
rescue Exception => e
|
15
|
+
puts "Redis support is unavailable. To use Redis do `gem install redis`"
|
9
16
|
end
|
10
17
|
|
11
18
|
Dir.glob(File.join(File.dirname(__FILE__), 'cachetastic', '**/*.rb')).sort.each do |f|
|
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.
|
4
|
+
version: 3.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/cachetastic/adapters/file.rb
|
79
79
|
- lib/cachetastic/adapters/local_memory.rb
|
80
80
|
- lib/cachetastic/adapters/memcached.rb
|
81
|
+
- lib/cachetastic/adapters/redis.rb
|
81
82
|
- lib/cachetastic/cache.rb
|
82
83
|
- lib/cachetastic/cacheable.rb
|
83
84
|
- lib/cachetastic/extensions/string.rb
|