torquebox-base 1.0.0.CR2-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
@@ -89,7 +89,12 @@ module ActiveSupport
|
|
89
89
|
def write_entry(key, entry, options = {})
|
90
90
|
args = [ :put_async, key, encode(entry) ]
|
91
91
|
args[0] = :put_if_absent_async if options[:unless_exist]
|
92
|
-
|
92
|
+
if options[:expires_in]
|
93
|
+
# Set the Infinispan expire a few minutes into the future to support
|
94
|
+
# :race_condition_ttl on read
|
95
|
+
expires_in = options[:expires_in].to_i + 5.minutes
|
96
|
+
args << expires_in << SECONDS
|
97
|
+
end
|
93
98
|
cache.send( *args ) && true
|
94
99
|
end
|
95
100
|
|
data/lib/torquebox-base.jar
CHANGED
Binary file
|
data/lib/torquebox-base.rb
CHANGED
@@ -105,6 +105,42 @@ describe ActiveSupport::Cache::TorqueBoxStore do
|
|
105
105
|
@cache.fetch("today", :force => true) { "Tuesday" }.should == "Tuesday"
|
106
106
|
end
|
107
107
|
|
108
|
+
it "should support :race_condition_ttl" do
|
109
|
+
database = mock('database')
|
110
|
+
fetch_options = { :expires_in => 0.1.seconds, :race_condition_ttl => 30.seconds }
|
111
|
+
# First fetch looks up from database and populates
|
112
|
+
database.should_receive(:town).and_return("Pantsville")
|
113
|
+
@cache.fetch("town", fetch_options) {
|
114
|
+
database.town
|
115
|
+
}.should == "Pantsville"
|
116
|
+
# Sleep until the entry is expired
|
117
|
+
sleep(0.2)
|
118
|
+
# Create a set of CountDownLatches to test :race_condition_ttl
|
119
|
+
# without relying on sleep calls
|
120
|
+
read_latch = java.util.concurrent.CountDownLatch.new(1)
|
121
|
+
write_latch = java.util.concurrent.CountDownLatch.new(1)
|
122
|
+
# Read the cache from two threads but only one should hit our database
|
123
|
+
database.should_receive(:town).once.and_return {
|
124
|
+
# Trigger the read latch so the other thread can read the cached value
|
125
|
+
read_latch.count_down
|
126
|
+
write_latch.await(15, java.util.concurrent.TimeUnit::SECONDS)
|
127
|
+
"NoPantsville"
|
128
|
+
}
|
129
|
+
other_thread = Thread.new {
|
130
|
+
read_latch.await(15, java.util.concurrent.TimeUnit::SECONDS)
|
131
|
+
@cache.fetch("town", fetch_options) {
|
132
|
+
database.town
|
133
|
+
}.should == "Pantsville"
|
134
|
+
# Trigger the write latch to update the cached value
|
135
|
+
write_latch.count_down
|
136
|
+
}
|
137
|
+
@cache.fetch("town", fetch_options) {
|
138
|
+
database.town
|
139
|
+
}.should == "NoPantsville"
|
140
|
+
other_thread.join
|
141
|
+
@cache.read("town").should == "NoPantsville"
|
142
|
+
end
|
143
|
+
|
108
144
|
end
|
109
145
|
|
110
146
|
describe "multiples" do
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torquebox-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 1.0.0
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
6
|
platform: java
|
7
7
|
authors: []
|
8
8
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-29 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -92,9 +92,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
97
|
+
version: "0"
|
98
98
|
requirements: []
|
99
99
|
|
100
100
|
rubyforge_project:
|