fresh-redis 0.8.1
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.
- checksums.yaml +7 -0
- data/lib/fresh_redis.rb +36 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03906a9b18c8b24e9808f716128bfb7d5c768cc9
|
4
|
+
data.tar.gz: 20c8cd5f4a16afaea988d3da41c4bb0cbb732905
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e3f56cd4b1c53a300c61f7230f865017937d0fe972539a7c216483654312552885cbd7a90f8397484b734e3fa610898c14621f1e4a63974f2ebf46ee4800493
|
7
|
+
data.tar.gz: 7013136ac24cdcd38e00c4b16e290f4cfef1bf0f1e381a63d61356835754aa822144a44b253d8864aaee1fe26d57539445408504bf6f5c1117750a8a720337c6
|
data/lib/fresh_redis.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class FreshRedis
|
2
|
+
def self.get(name)
|
3
|
+
content = $redis.get(name)
|
4
|
+
return content.present? ? JSON.parse(content) : content
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.freshen(name, expire_age = nil, format = :ruby, &blk)
|
8
|
+
self.unset(name) if self.skip_cache?
|
9
|
+
|
10
|
+
unless contents = $redis.get(name)
|
11
|
+
contents = self.set(name, blk.call())
|
12
|
+
$redis.expire(name, expire_age.seconds) if expire_age
|
13
|
+
end
|
14
|
+
|
15
|
+
contents = JSON.parse(contents) unless (format == :json)
|
16
|
+
|
17
|
+
return contents
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.set(name, contents)
|
21
|
+
contents = JSON.generate(contents)
|
22
|
+
$redis.set(name, contents)
|
23
|
+
|
24
|
+
return contents
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.unset(name)
|
28
|
+
return $redis.del(name) == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.skip_cache?
|
34
|
+
return ["development", "test"].include? RAILS_ENV
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fresh-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Connor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple wrapper around Redis in Ruby that provides easy mechanisms for
|
14
|
+
keeping your cache fresh, particularly with JSONm
|
15
|
+
email: danconn@danconnor.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/fresh_redis.rb
|
21
|
+
homepage: https://github.com/onyxrev/fresh-redis
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A simple wrapper around Redis in Ruby that provides easy mechanisms for keeping
|
45
|
+
your cache fresh, particularly with JSON
|
46
|
+
test_files: []
|