query_cache 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/query_cache/version.rb +3 -0
- data/lib/query_cache.rb +49 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1e5b1903b5542d23d26ff31bb5d0da3f14f3d95
|
4
|
+
data.tar.gz: c10ed3ec9683c1596e8bb3cc303bea48057fc564
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67d087d05aef2de3339aebb057956f3cfb4e0ca2b24978cc34b3846bffd688f729efa3c8202e67a8006b69bc4013598805bbe62691e7385eb4a436bbec046dae
|
7
|
+
data.tar.gz: 7d07ac2373e203ab7bb6d59e11b5d4945514c5194632a82a299fdc51f678667fe80c5b0f6b67548c4b18a4b3c0e1faea9a2aa398c09b4e9672219474c6c347f6
|
data/lib/query_cache.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "query_cache/version"
|
2
|
+
require "active_record"
|
3
|
+
require "rack/body_proxy"
|
4
|
+
|
5
|
+
# Usage example: (In config/environments/production.rb)
|
6
|
+
#
|
7
|
+
# config.middleware.insert_after ActiveRecord::QueryCache, QueryCache.for(MyBase)
|
8
|
+
#
|
9
|
+
# Original source:
|
10
|
+
# https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/query_cache.rb
|
11
|
+
module QueryCache
|
12
|
+
class Middleware
|
13
|
+
cattr_accessor :base
|
14
|
+
|
15
|
+
def initialize(app)
|
16
|
+
@app = app
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
connection = base.connection
|
21
|
+
enabled = connection.query_cache_enabled
|
22
|
+
connection_id = base.connection_id
|
23
|
+
connection.enable_query_cache!
|
24
|
+
|
25
|
+
response = @app.call(env)
|
26
|
+
response[2] = Rack::BodyProxy.new(response[2]) do
|
27
|
+
restore_query_cache_settings(connection_id, enabled)
|
28
|
+
end
|
29
|
+
|
30
|
+
response
|
31
|
+
ensure
|
32
|
+
restore_query_cache_settings(connection_id, enabled)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def restore_query_cache_settings(connection_id, enabled)
|
38
|
+
base.connection_id = connection_id
|
39
|
+
base.connection.clear_query_cache
|
40
|
+
base.connection.disable_query_cache! unless enabled
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.for(base)
|
45
|
+
fail ArgumentError, "You supllied `nil' instead of a ActiveRecord::Base subclass" if base.nil?
|
46
|
+
fail ArgumentError, "Must be subclass of ActiveRecord::Base" unless base <= ActiveRecord::Base
|
47
|
+
Class.new(Middleware).tap { |c| c.base = base }
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: query_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Haagen Michaelsen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
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: pry
|
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:
|
98
|
+
email:
|
99
|
+
- tobias.michaelsen@karnovgroup.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/query_cache.rb
|
105
|
+
- lib/query_cache/version.rb
|
106
|
+
homepage: https://github.com/karnov/query_cache
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.4.8
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Query cache middleware for custom ActiveRecord base classes.
|
130
|
+
test_files: []
|
131
|
+
has_rdoc:
|