request_local_cache 0.1.0

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: 199b15bcc76fc1dcefcc4b1f57fd550e983ec5f6
4
+ data.tar.gz: 370c14f545f69b70be7dcdcee3dfc00c9ccafae1
5
+ SHA512:
6
+ metadata.gz: c2de424c1cf36250965b05c2e0822fb9cd2618c47f8b010378c8a250d121d413bfd8e8183812b80c91a94e1cc46c54b9fa7ac872f6aaa4e6e3e09f2c0e8a2799
7
+ data.tar.gz: a39dd20c6a8ef4b7c8d052fd0b632caa68c13bbf153fa50e38711ab6a918d3b9abfb4410b067e32b8f29d53a0ab8ee1e6956d44b317d4369bdebc1381de41678
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in request_local_cache.gemspec
4
+ gemspec
@@ -0,0 +1,61 @@
1
+ # RequestLocalCache
2
+
3
+ Cache data per request basis.
4
+
5
+ Cache is created on request start and removed on request end.
6
+
7
+ Wraps `ActiveSupport::Cache::Strategy::LocalCache::LocalStore`.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'request_local_cache'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install request_local_cache
24
+
25
+ ## Usage
26
+
27
+ Call `RequestLocalCache.store` to get the instance of
28
+ `ActiveSupport::Cache::Strategy::LocalCache::LocalStore`, it is a in memory local store:
29
+ https://github.com/rails/rails/blob/4-2-stable/activesupport/lib/active_support/cache/strategy/local_cache.rb#L36
30
+
31
+ ```ruby
32
+ RequestLocalCache.store
33
+ => #<ActiveSupport::Cache::Strategy::LocalCache::LocalStore:0x0055995ed0d8e0 @data={}, @options={}>
34
+
35
+ RequestLocalCache.store.fetch('key') { :value }
36
+ => :value
37
+ ```
38
+
39
+ Public interface
40
+
41
+ ```ruby
42
+ ls RequestLocalCache.store
43
+ => ActiveSupport::Cache::Store#methods:
44
+ cleanup decrement delete delete_matched exist?
45
+ fetch fetch_multi
46
+ increment logger logger= mute options
47
+ read read_multi
48
+ silence silence! silence?
49
+ write
50
+ ```
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vinted/request_local_cache.
61
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'request_local_cache'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require 'request_local_cache/version'
2
+ require 'request_local_cache/middleware'
3
+ require 'request_local_cache/railtie' if defined?(Rails::Railtie)
4
+
5
+ module RequestLocalCache
6
+ def self.store
7
+ Thread.current[:request_local_store] ||=
8
+ ActiveSupport::Cache::Strategy::LocalCache::LocalStore.new
9
+ end
10
+
11
+ def self.clear!
12
+ Thread.current[:request_local_store] = nil
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module RequestLocalCache
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ RequestLocalCache.clear!
9
+ @app.call(env)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module RequestLocalCache
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'request_local_cache.insert_middleware' do |app|
4
+ if ActionDispatch.const_defined? :RequestId
5
+ app.config.middleware.insert_after ActionDispatch::RequestId, RequestLocalCache::Middleware
6
+ else
7
+ app.config.middleware.insert_after Rack::MethodOverride, RequestLocalCache::Middleware
8
+ end
9
+
10
+ if ActionDispatch.const_defined?(:Reloader) && ActionDispatch::Reloader.respond_to?(:to_cleanup)
11
+ ActionDispatch::Reloader.to_prepare do
12
+ RequestLocalCache.clear!
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module RequestLocalCache
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'request_local_cache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'request_local_cache'
8
+ spec.version = RequestLocalCache::VERSION
9
+ spec.authors = ['Karolis Astrauka']
10
+ spec.email = ['astrauka@gmail.com']
11
+
12
+ spec.summary = %q{RequestLocalCache gives you per-request cache}
13
+ spec.description = %q{RequestLocalCache gives you per-request cache}
14
+ spec.homepage = 'https://github.com/vinted/request_local_cache'
15
+ spec.licenses = ['MIT']
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'activesupport', '~> 4.2.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: request_local_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Karolis Astrauka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: RequestLocalCache gives you per-request cache
56
+ email:
57
+ - astrauka@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/request_local_cache.rb
69
+ - lib/request_local_cache/middleware.rb
70
+ - lib/request_local_cache/railtie.rb
71
+ - lib/request_local_cache/version.rb
72
+ - request_local_cache.gemspec
73
+ homepage: https://github.com/vinted/request_local_cache
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.5
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: RequestLocalCache gives you per-request cache
97
+ test_files: []