cachext 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +7 -2
- data/lib/cachext.rb +8 -0
- data/lib/cachext/configuration.rb +19 -0
- data/lib/cachext/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57e65ad4f06f5acff5ddc4d5b3554fb9bd49ec5
|
4
|
+
data.tar.gz: 964fed39f446dda576f5505a8489254718507a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a3e5777bcb4d6c4f0183e10c3738416f807ad8edb7102ba4fb4a08da3a340bf2f3e229bb113aaea4d310b751f68d01e6a6bdee2543e7cee7089322cfc6344fb
|
7
|
+
data.tar.gz: 8f4d957745f93daf3e20a6abf7dd5f3b1283a7d3a906410b97e64011a1aec0fcda2cf3153f202d3316d383296f51c50e78deee5686744e458668fc009af802f3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Cachext
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/dplummer/cachext.svg)](https://travis-ci.org/dplummer/cachext)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/cachext.svg)](https://badge.fury.io/rb/cachext)
|
5
|
+
|
3
6
|
Extensions to normal Rails caching:
|
4
7
|
|
5
8
|
* Lock (inspired by https://github.com/seamusabshere/lock_and_cache)
|
@@ -8,8 +11,10 @@ Extensions to normal Rails caching:
|
|
8
11
|
## Quickstart
|
9
12
|
|
10
13
|
```ruby
|
11
|
-
Cachext.
|
12
|
-
|
14
|
+
Cachext.configure do |config|
|
15
|
+
config.cache = Rails.cache
|
16
|
+
config.redis = Redis.current
|
17
|
+
end
|
13
18
|
|
14
19
|
key = [:foo, :bar, 1]
|
15
20
|
Cachext.fetch key, expires_in: 2.hours, default: "cow" do
|
data/lib/cachext.rb
CHANGED
@@ -30,6 +30,10 @@ module Cachext
|
|
30
30
|
@client ||= Client.new config
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.config=(new_config)
|
34
|
+
@config = new_config
|
35
|
+
end
|
36
|
+
|
33
37
|
def self.config
|
34
38
|
@config ||= Configuration.new
|
35
39
|
end
|
@@ -42,4 +46,8 @@ module Cachext
|
|
42
46
|
def self.multi klass, ids, options = {}, &block
|
43
47
|
Multi.new(config, klass, options).fetch ids, &block
|
44
48
|
end
|
49
|
+
|
50
|
+
def self.configure &block
|
51
|
+
@config = Configuration.setup(&block)
|
52
|
+
end
|
45
53
|
end
|
@@ -14,6 +14,25 @@ module Cachext
|
|
14
14
|
:debug, # output debug messages to STDERR
|
15
15
|
:heartbeat_expires # time in seconds for process heardbeat to expire
|
16
16
|
|
17
|
+
MissingConfiguration = Class.new(StandardError)
|
18
|
+
|
19
|
+
def self.setup
|
20
|
+
config = new
|
21
|
+
yield config
|
22
|
+
|
23
|
+
if config.cache.nil?
|
24
|
+
raise MissingConfiguration, "Must configure the config.cache. Try config.cache = Rails.cache"
|
25
|
+
end
|
26
|
+
|
27
|
+
if config.redis.nil?
|
28
|
+
raise MissingConfiguration, "Must configure the config.redis. Try config.redis = Redis.current"
|
29
|
+
end
|
30
|
+
|
31
|
+
config.lock_manager
|
32
|
+
|
33
|
+
config
|
34
|
+
end
|
35
|
+
|
17
36
|
def initialize
|
18
37
|
self.raise_errors = false
|
19
38
|
self.default_errors = [
|
data/lib/cachext/version.rb
CHANGED