redis-renew 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3f9e7855628bb6be70245699311eb7b6f7c77f0
4
+ data.tar.gz: 17c292c55ccf893346e2967badb2ed780ef843bc
5
+ SHA512:
6
+ metadata.gz: 7b83c10b037b346be90cc63a627180346145fe8f1720cd6618def9ddd44552e98d1d020d71c9f82dda902505a318c19190608b167bdd5f53f2e067a4be6f19bd
7
+ data.tar.gz: 12e0c93a83c2ffd044173eb3d005ee8ec9fe1bc366a27d6216724184b51f60cc58c3ca9060b3c2f8341d1ede7da9e38265d9d5bb260ee25eff823af31cb55122
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.ruby-*
4
+ *.swp
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis-renew.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brandon Dewitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Redis::Renew
2
+
3
+ Attempts to solve the problem of cache keys that are accessed being extended by a known value each time it is accessed.
4
+ This helps by keeping frequently accessed cache keys in the redis cache without having to store the key again.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'redis-renew'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install redis-renew
19
+
20
+ ## Usage
21
+ With Rails
22
+
23
+ ```ruby
24
+ # application.rb
25
+
26
+ module Appthing
27
+ class Application < ::Rails::Application
28
+ # setup Rails.cache to be redis_renew
29
+ # and set the renewal expiry to be 30 seconds
30
+ # with each access the expiry is extended 30 seconds
31
+ config.cache_store = :redis_renew, config.redis_connections['cache'], :renew_expires_in => 30.seconds
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ # encoding: UTF-8
2
+ require 'redis-activesupport'
3
+ require 'redis-store'
4
+
5
+ module ActiveSupport
6
+ module Cache
7
+ class RedisRenew < RedisStore
8
+ protected
9
+
10
+ def read_entry(key, local_options)
11
+ renew_expires_in = options[:renew_expires_in] || local_options[:expires_in] || nil
12
+ return super unless renew_expires_in # bail if no renewal desired
13
+
14
+ if connection_supports_multi?
15
+ replies = @data.multi do |multi|
16
+ multi.get(key, local_options)
17
+ multi.expire(key, renew_expires_in)
18
+ end
19
+
20
+ entry = replies.first
21
+
22
+ case
23
+ when entry && entry.is_a?(ActiveSupport::Cache::Entry) then
24
+ entry
25
+ when entry then
26
+ ActiveSupport::Cache::Entry.new(entry)
27
+ else
28
+ nil
29
+ end
30
+ else
31
+ entry = super # do nothing and manually reset expiry
32
+ expire(key, renew_expires_in)
33
+ entry
34
+ end
35
+ rescue Errno::ECONNREFUSED, Redis::CannotConnectError
36
+ nil
37
+ end
38
+
39
+ private
40
+
41
+ def connection_supports_multi?
42
+ @data.respond_to?(:multi)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,2 @@
1
+ require "redis-renew/version"
2
+ require "active_support/cache/redis_renew"
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ module Renew
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis-renew/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "redis-renew"
8
+ gem.version = Redis::Renew::VERSION
9
+ gem.authors = ["Brandon Dewitt"]
10
+ gem.email = ["brandonsdewitt@gmail.com"]
11
+ gem.description = %q{ Simple gem that extends redis expiry of keys when accessed }
12
+ gem.summary = %q{ Simple gem that extends redis expiry of keys when accessed }
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'redis-store'
21
+ gem.add_dependency 'redis-activesupport'
22
+
23
+ gem.add_development_dependency 'rake'
24
+ gem.add_development_dependency 'bundler'
25
+ gem.add_development_dependency 'mocha'
26
+ gem.add_development_dependency 'minitest'
27
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-renew
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis-store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis-activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: " Simple gem that extends redis expiry of keys when accessed "
98
+ email:
99
+ - brandonsdewitt@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/active_support/cache/redis_renew.rb
110
+ - lib/redis-renew.rb
111
+ - lib/redis-renew/version.rb
112
+ - redis-renew.gemspec
113
+ homepage: ''
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Simple gem that extends redis expiry of keys when accessed
136
+ test_files: []