cachetastic 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +13 -17
  2. data/lib/cachetastic/cache.rb +37 -7
  3. metadata +4 -4
data/README CHANGED
@@ -1,19 +1,16 @@
1
1
  =What is Cachetastic?
2
- Cachetastic is an incredibly easy to use and administer caching framework. Just because it is easy to use, does not mean that
3
- it is light with features. Cachetastic allows you to create classes that extend <tt>Cachetastic::Cache</tt>, configure them
4
- each individually, and much more.
5
2
 
6
- Unlike other systems each cache in your system can use different backends via the use of adapters that get assigned to each
7
- cache, and globally. You can define different expiration times, loggers, marshal methods, and more! And again, you can choose to
8
- define these settings globally, or for each cache!
3
+ Cachetastic is an incredibly easy to use and administer caching framework. Just because it is easy to use, does not mean that it is light with features. Cachetastic allows you to create classes that extend <code>Cachetastic::Cache</code>, configure them each individually, and much more.
4
+
5
+ Unlike other systems each cache in your system can use different backends via the use of adapters that get assigned to each cache, and globally. You can define different expiration times, loggers, marshal methods, and more! And again, you can choose to define these settings globally, or for each cache!
9
6
 
10
7
  Adapters are easy to write, so if the built in adapters don't float your boat, you can easily knock one off in short order.
11
8
 
12
9
  ==Configuration:
13
- Configuration of Cachetastic is done using the Configatron gem. I would recommend reading the documentation on it first, http://configatron.mackframework.com, before continuing.
14
10
 
15
- All configuration settings hang off of the <tt>cachetastic</tt> namespace on <tt>configatron</tt>. The default settings
16
- all hang off the <tt>defaults</tt> namespace on the <tt>cachetastic</tt> namespace, as shown below:
11
+ Configuration of Cachetastic is done using the Configatron gem. I would recommend reading the documentation on it first, hcodep://configatron.mackframework.com, before continuing.
12
+
13
+ All configuration settings hang off of the <code>cachetastic</code> namespace on <code>configatron</code>. The default settings all hang off the <code>defaults</code> namespace on the <code>cachetastic</code> namespace, as shown below:
17
14
 
18
15
  # This will write detailed information to the logger.
19
16
  configatron.cachetastic.defaults.debug = false
@@ -34,7 +31,7 @@ all hang off the <tt>defaults</tt> namespace on the <tt>cachetastic</tt> namespa
34
31
  # This sets how long objects will live in the cache before they are auto expired.
35
32
  configatron.cachetastic.defaults.default_expiry = 86400 # time in seconds (default: 24 hours)
36
33
 
37
- # When setting objects into the cache the expiry_swing is +/- to the expiry time.
34
+ # When secodeing objects into the cache the expiry_swing is +/- to the expiry time.
38
35
  # Example: if the expiry time is 1 minute, and the swing is 15 seconds,
39
36
  # objects will go into the cache with an expiry time sometime between 45 seconds and 75 seconds.
40
37
  # The default is 0 seconds.
@@ -47,7 +44,7 @@ all hang off the <tt>defaults</tt> namespace on the <tt>cachetastic</tt> namespa
47
44
  log_2 = Logger.new("log/cachetastic.log")
48
45
  log_2.level = Logger::ERROR
49
46
  configatron.cachetastic.defaults.logger = [log_1, log_2]
50
-
47
+
51
48
  Overriding settings per cache is very simple. Let's take the following two caches:
52
49
 
53
50
  class UserCache < Cachetastic::Cache
@@ -56,14 +53,13 @@ Overriding settings per cache is very simple. Let's take the following two cache
56
53
  class Admin::UserCache < Cachetastic::Cache
57
54
  end
58
55
 
59
- If we wanted to set the <tt>UserCache</tt> to use the <tt>Cachetastic::Adapters::File</tt> adapter and we wanted to set the adapter for
60
- the <tt>Admin::UserCache</tt> to use <tt>Cachetastic::Adapters::Memcached</tt>, we would configure them like such:
56
+ If we wanted to set the <code>UserCache</code> to use the <code>Cachetastic::Adapters::File</code> adapter and we wanted to set the adapter for
57
+ the <code>Admin::UserCache</code> to use <code>Cachetastic::Adapters::Memcached</code>, we would configure them like such:
61
58
 
62
59
  configatron.cachetastic.user_cache.adapter = Cachetastic::Adapters::File
63
60
  configatron.cachetastic.admin.user_cache.adapter = Cachetastic::Adapters::Memcached
64
-
65
- In this scenario we have changed the adapters for each of the classes. All of the other default settings will remain intact for
66
- each of those classes. This makes it incredibly easy to just change the one parameter you need, and not have to reset them all.
61
+
62
+ In this scenario we have changed the adapters for each of the classes. All of the other default settings will remain intact for each of those classes. This makes it incredibly easy to just change the one parameter you need, and not have to reset them all.
67
63
 
68
64
  ==Examples:
69
65
 
@@ -86,4 +82,4 @@ each of those classes. This makes it incredibly easy to just change the one para
86
82
  end
87
83
 
88
84
  MyAwesomeCache.get(1, 2, 4) # => 8
89
- MyAwesomeCache.get(1, 4, 4) # => 8
85
+ MyAwesomeCache.get(1, 4, 4) # => 8
@@ -40,8 +40,10 @@ module Cachetastic # :nodoc:
40
40
  # results of the block are not automatically cached.
41
41
  def get(key, &block)
42
42
  do_with_logging(:get, key) do
43
- val = self.adapter.get(key)
44
- handle_store_object(key, adapter.unmarshal(val), &block)
43
+ retryable do
44
+ val = self.adapter.get(key)
45
+ handle_store_object(key, adapter.unmarshal(val), &block)
46
+ end
45
47
  end
46
48
  end # get
47
49
 
@@ -55,23 +57,29 @@ module Cachetastic # :nodoc:
55
57
  # expiry time.
56
58
  def set(key, value, expiry_time = nil)
57
59
  do_with_logging(:set, key) do
58
- self.adapter.set(key, value, calculate_expiry_time(expiry_time))
60
+ retryable do
61
+ self.adapter.set(key, value, calculate_expiry_time(expiry_time))
62
+ end
59
63
  end
60
64
  end # set
61
65
 
62
66
  # Deletes an object from the cache.
63
67
  def delete(key)
64
68
  do_with_logging(:delete, key) do
65
- self.adapter.delete(key)
66
- nil
69
+ retryable do
70
+ self.adapter.delete(key)
71
+ nil
72
+ end
67
73
  end
68
74
  end # delete
69
75
 
70
76
  # Expires all objects for this cache.
71
77
  def expire_all
72
78
  do_with_logging(:expire_all, nil) do
73
- self.adapter.expire_all
74
- nil
79
+ retryable do
80
+ self.adapter.expire_all
81
+ nil
82
+ end
75
83
  end
76
84
  end # expire_all
77
85
 
@@ -159,6 +167,28 @@ module Cachetastic # :nodoc:
159
167
  end
160
168
  end
161
169
 
170
+ def retryable(options = {}, &block)
171
+ opts = { :tries => 2, :on => Exception }.merge(options)
172
+
173
+ retries = opts[:tries]
174
+ retry_exceptions = [opts[:on]].flatten
175
+
176
+ x = %{
177
+ begin
178
+ return yield
179
+ rescue #{retry_exceptions.join(", ")} => e
180
+ retries -= 1
181
+ if retries > 0
182
+ retry
183
+ else
184
+ raise e
185
+ end
186
+ end
187
+ }
188
+
189
+ eval(x, &block)
190
+ end
191
+
162
192
  end # class << self
163
193
 
164
194
  end # Cache
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - Mark Bates
7
+ - markbates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-03 00:00:00 -04:00
12
+ date: 2009-08-31 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.3.2
44
44
  version:
45
45
  description: A very simple, yet very powerful caching framework for Ruby.
46
- email: mark@mackframework.com
46
+ email: mark@markbates.com
47
47
  executables: []
48
48
 
49
49
  extensions: []