egalite 1.5.13 → 1.5.14
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 +4 -4
- data/lib/egalite/cache.rb +22 -4
- data/lib/egalite/version.rb +1 -1
- data/test/test_cache.rb +91 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a9c5192532b745af1b9af582f08661f470a8080
|
4
|
+
data.tar.gz: 168d9cd38658b514c908168c89c8460e0571b2a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8579ab001b10cb885fadd5d7c181dbe268c2ba58614911c77e12d2175285f6562d4fa0af9e163d0e7dd8030806d6bb29d1c3e2c51d8bac41151221814702bd09
|
7
|
+
data.tar.gz: 39de9fbccf6d700ab26a0d5da58dc89aa4533f2b0d284a4f1f0b55b3319a011dbe8c5ca66f29db195f806630cc10cc4fd1da6318c3e706cf17d11032427c93d8
|
data/lib/egalite/cache.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
CREATE TABLE controller_cache (
|
6
6
|
id SERIAL PRIMARY KEY,
|
7
7
|
inner_path TEXT NOT NULL,
|
8
|
+
query_string TEXT,
|
8
9
|
language TEXT,
|
9
10
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
10
11
|
content TEXT NOT NULL
|
@@ -19,6 +20,14 @@ module Egalite
|
|
19
20
|
def create_table(db, opts = {})
|
20
21
|
table = opts[:table_name] || :controller_cache
|
21
22
|
|
23
|
+
create_table_without_query(db, opts)
|
24
|
+
db.alter_table(table) {
|
25
|
+
add_column :query_string, :varchar
|
26
|
+
}
|
27
|
+
end
|
28
|
+
def create_table_without_query(db, opts = {})
|
29
|
+
table = opts[:table_name] || :controller_cache
|
30
|
+
|
22
31
|
db.create_table(table) {
|
23
32
|
primary_key :id, :integer, :auto_increment => true
|
24
33
|
column :inner_path, :varchar
|
@@ -38,14 +47,21 @@ module Egalite
|
|
38
47
|
def self.included(base)
|
39
48
|
base.extend(ClassMethods)
|
40
49
|
end
|
41
|
-
def __controller_cache__dataset
|
50
|
+
def __controller_cache__dataset(options)
|
42
51
|
table = Egalite::ControllerCache.table
|
43
52
|
dataset = table.filter(:inner_path => req.inner_path)
|
53
|
+
if options[:with_query]
|
54
|
+
dataset = dataset.filter(:query_string => __query_string(options))
|
55
|
+
end
|
44
56
|
if req.language
|
45
57
|
dataset = dataset.filter(:language => req.language)
|
46
58
|
end
|
47
59
|
dataset
|
48
60
|
end
|
61
|
+
def __query_string(options)
|
62
|
+
return nil unless options[:with_query] and not req.rack_request.query_string.empty?
|
63
|
+
req.rack_request.query_string
|
64
|
+
end
|
49
65
|
def before_filter
|
50
66
|
cache = self.class.controller_cache_actions[req.action_method]
|
51
67
|
if cache and Egalite::ControllerCache.table
|
@@ -53,7 +69,7 @@ module Egalite
|
|
53
69
|
if result != true
|
54
70
|
return result
|
55
71
|
end
|
56
|
-
dataset = __controller_cache__dataset
|
72
|
+
dataset = __controller_cache__dataset(cache)
|
57
73
|
record = dataset.first
|
58
74
|
return true unless record
|
59
75
|
return true if record[:updated_at] < (Time.now - cache[:expire])
|
@@ -66,13 +82,16 @@ module Egalite
|
|
66
82
|
html = super(html)
|
67
83
|
cache = self.class.controller_cache_actions[req.action_method]
|
68
84
|
if cache and Egalite::ControllerCache.table
|
69
|
-
dataset = __controller_cache__dataset
|
85
|
+
dataset = __controller_cache__dataset(cache)
|
70
86
|
data = {
|
71
87
|
:inner_path => req.inner_path,
|
72
88
|
:language => req.language,
|
73
89
|
:updated_at => Time.now,
|
74
90
|
:content => html,
|
75
91
|
}
|
92
|
+
if cache[:with_query]
|
93
|
+
data[:query_string] = __query_string(cache)
|
94
|
+
end
|
76
95
|
if dataset.count > 0
|
77
96
|
dataset.update(data)
|
78
97
|
else
|
@@ -83,4 +102,3 @@ module Egalite
|
|
83
102
|
end
|
84
103
|
end
|
85
104
|
end
|
86
|
-
|
data/lib/egalite/version.rb
CHANGED
data/test/test_cache.rb
CHANGED
@@ -25,6 +25,19 @@ class TestCacheController < Egalite::Controller
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
class TestCachewithqueryController < Egalite::Controller
|
29
|
+
include Egalite::ControllerCache
|
30
|
+
|
31
|
+
cache_action :get, :expire => 1, :with_query => true
|
32
|
+
|
33
|
+
def get
|
34
|
+
"#{Time.now.to_i}.#{Time.now.usec}"
|
35
|
+
end
|
36
|
+
def nocache
|
37
|
+
"#{Time.now.to_i}.#{Time.now.usec}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
28
41
|
class CacheController < Egalite::Controller
|
29
42
|
include Egalite::ControllerCache
|
30
43
|
|
@@ -41,6 +54,47 @@ class CacheController < Egalite::Controller
|
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
57
|
+
# compatibility test
|
58
|
+
class T_CacheWithoutQuery < Test::Unit::TestCase
|
59
|
+
include Rack::Test::Methods
|
60
|
+
|
61
|
+
def app
|
62
|
+
db = Sequel.sqlite
|
63
|
+
Egalite::ControllerCache.create_table_without_query(db)
|
64
|
+
Egalite::ControllerCache.table = db[:controller_cache]
|
65
|
+
Egalite::Handler.new
|
66
|
+
end
|
67
|
+
def test_cache
|
68
|
+
# test cache is not working
|
69
|
+
get "/test/cache/nocache"
|
70
|
+
a = last_response.body
|
71
|
+
sleep 0.1
|
72
|
+
get "/test/cache/nocache"
|
73
|
+
b = last_response.body
|
74
|
+
assert_not_equal a,b
|
75
|
+
|
76
|
+
# test cache is working
|
77
|
+
get "/test/cache/"
|
78
|
+
a = last_response.body
|
79
|
+
sleep 0.1
|
80
|
+
get "/test/cache/"
|
81
|
+
b = last_response.body
|
82
|
+
assert_equal a,b
|
83
|
+
sleep 2
|
84
|
+
get "/test/cache/"
|
85
|
+
c = last_response.body
|
86
|
+
assert_not_equal a,c
|
87
|
+
|
88
|
+
# test cache is not working for different url
|
89
|
+
get "/test/cache/1"
|
90
|
+
a = last_response.body
|
91
|
+
sleep 0.1
|
92
|
+
get "/test/cache/2"
|
93
|
+
b = last_response.body
|
94
|
+
assert_not_equal a,b
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
44
98
|
class T_Cache < Test::Unit::TestCase
|
45
99
|
include Rack::Test::Methods
|
46
100
|
|
@@ -79,6 +133,43 @@ class T_Cache < Test::Unit::TestCase
|
|
79
133
|
b = last_response.body
|
80
134
|
assert_not_equal a,b
|
81
135
|
end
|
136
|
+
def test_cache_with_query
|
137
|
+
# test cache is not working
|
138
|
+
get "/test/cachewithquery/nocache"
|
139
|
+
a = last_response.body
|
140
|
+
sleep 0.1
|
141
|
+
get "/test/cachewithquery/nocache"
|
142
|
+
b = last_response.body
|
143
|
+
assert_not_equal a,b
|
144
|
+
|
145
|
+
# test cache is working
|
146
|
+
get "/test/cachewithquery?a=1"
|
147
|
+
a = last_response.body
|
148
|
+
sleep 0.1
|
149
|
+
get "/test/cachewithquery?a=1"
|
150
|
+
b = last_response.body
|
151
|
+
assert_equal a,b
|
152
|
+
sleep 2
|
153
|
+
get "/test/cachewithquery?a=1"
|
154
|
+
c = last_response.body
|
155
|
+
assert_not_equal a,c
|
156
|
+
|
157
|
+
# test cache is not working for different url
|
158
|
+
get "/test/cachewithquery?a=1"
|
159
|
+
a = last_response.body
|
160
|
+
sleep 0.1
|
161
|
+
get "/test/cachewithquery"
|
162
|
+
b = last_response.body
|
163
|
+
assert_not_equal a,b
|
164
|
+
sleep 0.1
|
165
|
+
get "/test/cachewithquery?a=2"
|
166
|
+
c = last_response.body
|
167
|
+
assert_not_equal a,c
|
168
|
+
sleep 0.1
|
169
|
+
get "/test/cachewithquery?a=1&b=2"
|
170
|
+
d = last_response.body
|
171
|
+
assert_not_equal a,d
|
172
|
+
end
|
82
173
|
end
|
83
174
|
|
84
175
|
# テンプレートでのテスト
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egalite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shunichi Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|