h2ocube_rails_cache 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 852632a99122d3c7d6e43f558eae3898224cca40
4
- data.tar.gz: debe972dfae26a1bf1d03db710e01fe187d01ae4
3
+ metadata.gz: 2348a9736459123e522839e417ab16b2e68651b9
4
+ data.tar.gz: e321a73a80995cd9d90cae7342ddce29915c6a56
5
5
  SHA512:
6
- metadata.gz: d5cfbff54d12754f1696e340a7f944d74d1ac99fe889d66d6037b334e8f5989f80948b79b6a17c51d401501127e578b9b54f67d888c2080928c9863ae6b0d1ad
7
- data.tar.gz: 89f781daf9a6948600a8d0c4f640ed81428e9ec8b827810f88cd0eea52cda64e61a35ee26cdb1a427b94f2d56ad59c2349fc1f3c23e96fc0bbf778a000d6869f
6
+ metadata.gz: 0cb15088fee644512bbdcfde93acb5ebcde226bec3e77577d116a5f0be992d7825f1e9e108849f0f8271fed9e38a587ca5d80384b158c4c888a8d14e1bb0f87e
7
+ data.tar.gz: a4f720931709e2c815da75d399588e29b65aacb9440498133064d1b9d85faec81058add8bd94fc28a0a4375494758d473cf929147702bbda29ffe05e3b44e501
data/README.md CHANGED
@@ -17,6 +17,19 @@ And then execute:
17
17
 
18
18
  Disable default session_store in config/initializers/session_store.rb
19
19
 
20
+ ## Rails.cache support methods
21
+
22
+ * `keys key = '*'`
23
+ * `read key, options = nil`
24
+ * `write key, entry, options = nil`
25
+ * `fetch key, options = nil, &blk`
26
+ * `delete key, options = nil`
27
+ * `exist? key, options = nil`
28
+ * `increment key, amount = 1, options = nil`
29
+ * `decrement key, amount = 1, options = nil`
30
+ * `clear`
31
+ * `info`
32
+
20
33
  ## Task changed
21
34
 
22
35
  rake tmp:sessions:clear # will clear redis session data too
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'h2ocube_rails_cache'
7
- gem.version = '0.0.7'
7
+ gem.version = '0.0.8'
8
8
  gem.authors = ['Ben']
9
9
  gem.email = ['ben@h2ocube.com']
10
10
  gem.description = 'Just an redis cache.'
@@ -15,10 +15,12 @@ module ActiveSupport
15
15
  @data.keys key
16
16
  end
17
17
 
18
- def fetch key, options = nil
18
+ def fetch key, options = nil, &blk
19
19
  key = expanded_key key
20
- write key, yield, options if block_given? && !exist?(key)
21
- read key, options
20
+
21
+ return read(key, options) if exist?(key)
22
+
23
+ write key, blk, options if block_given?
22
24
  end
23
25
 
24
26
  def read key, options = nil
@@ -40,8 +42,14 @@ module ActiveSupport
40
42
  def write key, entry, options = nil
41
43
  key = expanded_key key
42
44
  return false if key.start_with?('http')
43
- @data.set key, dump_entry(entry), options
44
- true
45
+ entry = dump_entry entry
46
+ if entry.nil?
47
+ Rails.logger.warn "CacheWarn: '#{key}' is not cacheable!"
48
+ nil
49
+ else
50
+ @data.set key, entry, options
51
+ load_entry entry
52
+ end
45
53
  end
46
54
 
47
55
  def delete key, options = nil
@@ -90,11 +98,17 @@ module ActiveSupport
90
98
 
91
99
  def dump_entry entry
92
100
  entry = entry.call if entry.class.to_s == 'Proc'
101
+
93
102
  case entry.class.to_s
94
103
  when 'String', 'Fixnum', 'Float'
95
104
  entry
96
105
  else
97
- Marshal.dump entry
106
+ begin
107
+ Marshal.dump entry
108
+ rescue Exception => e
109
+ Rails.logger.error "CacheError: #{e}"
110
+ return nil
111
+ end
98
112
  end
99
113
  end
100
114
 
data/test/cache_test.rb CHANGED
@@ -101,6 +101,16 @@ describe 'h2ocube_rails_cache' do
101
101
  sleep 2
102
102
  Rails.cache.exist?('fetch expire').must_be_same_as false
103
103
  end
104
+
105
+ it 'fetch with error block' do
106
+ Rails.cache.fetch 'fetch error' do
107
+ {
108
+ proc: -> {}
109
+ }
110
+ end.must_be_nil
111
+
112
+ Rails.cache.exist?('fetch error').must_be_same_as false
113
+ end
104
114
  end
105
115
 
106
116
  describe ApplicationController do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: h2ocube_rails_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-namespace