torquebox-caching 4.0.0.alpha1-java
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 +7 -0
- data/lib/active_support/cache/torque_box_store.rb +111 -0
- data/lib/active_support/cache/torquebox_store.rb +2 -0
- data/lib/torquebox/caching/cache.rb +336 -0
- data/lib/torquebox/caching.rb +138 -0
- data/lib/torquebox-caching.rb +21 -0
- data/lib/wunderboss-jars/infinispan-commons-6.0.2.Final.jar +0 -0
- data/lib/wunderboss-jars/infinispan-core-6.0.2.Final.jar +0 -0
- data/lib/wunderboss-jars/jboss-marshalling-1.4.4.Final.jar +0 -0
- data/lib/wunderboss-jars/jboss-marshalling-river-1.4.4.Final.jar +0 -0
- data/lib/wunderboss-jars/jboss-transaction-api_1.1_spec-1.0.1.Final.jar +0 -0
- data/lib/wunderboss-jars/wunderboss-caching-1.x.incremental.174.jar +0 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e27cd0727836afa968aea5b75379557c9429cec
|
4
|
+
data.tar.gz: 7f1ab4734d94126d0084f3b02a8bdbb07acecc72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1e062ff99f81243df3e3bc0d26aa376b725fc72179ebe573907b899d1e6349c3b09177b61df39432819334ab3ed4e36488d0af7c5cd73820032c2985b25ab33
|
7
|
+
data.tar.gz: 47bb70cf25ff0f336dabc59ed3a1ab83c930bfe43dc827ade899750f8087bab86d7758d61e36d43eb6fb4c3675fa8782c55d5f9788fef4a518b9586cc686780d
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright 2014 Red Hat, Inc, and individual contributors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'active_support/cache'
|
16
|
+
require 'torquebox/caching'
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
module ActiveSupport
|
20
|
+
module Cache
|
21
|
+
# @api public
|
22
|
+
class TorqueBoxStore < Store
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
if (ttl = options.delete(:expires_in))
|
26
|
+
options[:ttl] = ttl.in_milliseconds
|
27
|
+
end
|
28
|
+
@name = options.delete(:name) || '__torquebox_store__'
|
29
|
+
super(options)
|
30
|
+
cache
|
31
|
+
end
|
32
|
+
|
33
|
+
# Clear the entire cache. Be careful with this method since it could
|
34
|
+
# affect other processes if shared cache is being used.
|
35
|
+
def clear(_options = nil)
|
36
|
+
cache.clear
|
37
|
+
end
|
38
|
+
|
39
|
+
# Delete all entries with keys matching the pattern.
|
40
|
+
def delete_matched(matcher, options = nil)
|
41
|
+
options = merged_options(options)
|
42
|
+
pattern = key_matcher(matcher, options)
|
43
|
+
keys.each { |key| delete(key, options) if key =~ pattern }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Increment an integer value in the cache; return new value
|
47
|
+
def increment(name, amount = 1, options = nil)
|
48
|
+
options = merged_options(options)
|
49
|
+
|
50
|
+
# Get the current entry
|
51
|
+
key = namespaced_key(name, options)
|
52
|
+
current = read_entry(key, options)
|
53
|
+
value = current.value.to_i
|
54
|
+
|
55
|
+
new_entry = Entry.new(value + amount, options)
|
56
|
+
if cache.compare_and_set(key, current, new_entry)
|
57
|
+
return new_entry.value
|
58
|
+
else
|
59
|
+
raise "Concurrent modification, old value was #{value}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Decrement an integer value in the cache; return new value
|
64
|
+
def decrement(name, amount = 1, options = nil)
|
65
|
+
increment(name, -amount, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Cleanup the cache by removing expired entries.
|
69
|
+
def cleanup(options = nil)
|
70
|
+
options = merged_options(options)
|
71
|
+
keys.each do |key|
|
72
|
+
entry = read_entry(key, options)
|
73
|
+
delete_entry(key, options) if entry && entry.expired?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
def defaults
|
80
|
+
{ :mode => :invalidation_async }
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return the keys in the cache; potentially very expensive depending on configuration
|
84
|
+
def keys
|
85
|
+
cache.keys
|
86
|
+
end
|
87
|
+
|
88
|
+
# Read an entry from the cache implementation. Subclasses must implement this method.
|
89
|
+
def read_entry(key, _options)
|
90
|
+
cache.get(key)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Write an entry to the cache implementation. Subclasses must implement this method.
|
94
|
+
def write_entry(key, entry, options = {})
|
95
|
+
options[:unless_exist] ? cache.put_if_absent(key, entry) : cache.put(key, entry)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Delete an entry from the cache implementation. Subclasses must implement this method.
|
99
|
+
def delete_entry(key, _options) # :nodoc:
|
100
|
+
cache.remove(key) && true
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def cache
|
107
|
+
@cache ||= TorqueBox::Caching.cache(@name, defaults.merge(options))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,336 @@
|
|
1
|
+
# Copyright 2014 Red Hat, Inc, and individual contributors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'forwardable'
|
16
|
+
|
17
|
+
java_import java.util.concurrent::TimeUnit
|
18
|
+
java_import org.projectodd.wunderboss.caching.notifications::Listener
|
19
|
+
|
20
|
+
module TorqueBox
|
21
|
+
module Caching
|
22
|
+
class Cache
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
# Wraps a real Infinispan cache object with a slightly simpler
|
26
|
+
# interface. The wrapped cache is available via the {#cache}
|
27
|
+
# accessor.
|
28
|
+
#
|
29
|
+
# @param cache [org.infinispan.Cache] The wrapped cache
|
30
|
+
# @param options [Hash] Options for entry expiration
|
31
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
32
|
+
# live before expiry
|
33
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
34
|
+
# entry will expire if not accessed
|
35
|
+
def initialize(cache, options = {})
|
36
|
+
@cache = cache
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
# Associate key to value in the cache. Expiration options
|
41
|
+
# override any passed to the constructor.
|
42
|
+
#
|
43
|
+
# @param key [Object]
|
44
|
+
# @param value [Object]
|
45
|
+
# @param options [Hash] Options for entry expiration
|
46
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
47
|
+
# live before expiry
|
48
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
49
|
+
# entry will expire if not accessed
|
50
|
+
# @return [Object] the old value, if any
|
51
|
+
def put(key, value, options = {})
|
52
|
+
put_m.call(*[key, value] + expiry(options))
|
53
|
+
end
|
54
|
+
|
55
|
+
# Put a map of entries into the cache. Expiration options
|
56
|
+
# override any passed to the constructor.
|
57
|
+
#
|
58
|
+
# @param map [Hash]
|
59
|
+
# @param options [Hash] Options for entry expiration
|
60
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
61
|
+
# live before expiry
|
62
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
63
|
+
# entry will expire if not accessed
|
64
|
+
# @return [void]
|
65
|
+
def put_all(map, options = {})
|
66
|
+
putall_m.call(*[map] + expiry(options))
|
67
|
+
end
|
68
|
+
|
69
|
+
# Associate key to value only if key doesn't exist in cache.
|
70
|
+
# Expiration options override any passed to the constructor.
|
71
|
+
#
|
72
|
+
# @param key [Object]
|
73
|
+
# @param value [Object]
|
74
|
+
# @param options [Hash] Options for entry expiration
|
75
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
76
|
+
# live before expiry
|
77
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
78
|
+
# entry will expire if not accessed
|
79
|
+
# @return [Object] nil on success, otherwise the old value
|
80
|
+
def put_if_absent(key, value, options = {})
|
81
|
+
putif_m.call(*[key, value] + expiry(options))
|
82
|
+
end
|
83
|
+
|
84
|
+
# Associate key to value only if key exists in cache. Expiration
|
85
|
+
# options override any passed to the constructor.
|
86
|
+
#
|
87
|
+
# @param key [Object]
|
88
|
+
# @param value [Object]
|
89
|
+
# @param options [Hash] Options for entry expiration
|
90
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
91
|
+
# live before expiry
|
92
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
93
|
+
# entry will expire if not accessed
|
94
|
+
# @return [Object] the old value on success, otherwise nil
|
95
|
+
def replace(key, value, options = {})
|
96
|
+
replace_m.call(*[key, value] + expiry(options))
|
97
|
+
end
|
98
|
+
|
99
|
+
# Associate key to a new value only if it's currently mapped to
|
100
|
+
# a specific value. Expiration options override any passed to
|
101
|
+
# the constructor.
|
102
|
+
#
|
103
|
+
# @param key [Object] the key
|
104
|
+
# @param old_value [Object] the current value of the key
|
105
|
+
# @param new_value [Object] the desired value of the key
|
106
|
+
# @param options [Hash] Options for entry expiration
|
107
|
+
# @option options :ttl [Number] (-1) milliseconds the entry will
|
108
|
+
# live before expiry
|
109
|
+
# @option options :idle [Number] (-1) milliseconds after which an
|
110
|
+
# entry will expire if not accessed
|
111
|
+
# @return [true, false] true if value successfully replaced
|
112
|
+
def compare_and_set(key, old_value, new_value, options = {})
|
113
|
+
cas_m.call(*[key, old_value, new_value] + expiry(options))
|
114
|
+
end
|
115
|
+
|
116
|
+
# Clear all entries from the cache
|
117
|
+
#
|
118
|
+
# @return [void]
|
119
|
+
def clear
|
120
|
+
@cache.clear
|
121
|
+
self
|
122
|
+
end
|
123
|
+
|
124
|
+
# Infinispan's cache notifications API is based on Java
|
125
|
+
# annotations, which can be awkward in JRuby (and Java, for that
|
126
|
+
# matter).
|
127
|
+
#
|
128
|
+
# This function provides the ability to map one or more symbols
|
129
|
+
# to a block that will be passed an
|
130
|
+
# {https://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/notifications/cachelistener/event/package-summary.html
|
131
|
+
# Infinispan Event} instance.
|
132
|
+
#
|
133
|
+
# Each symbol corresponds to an event type, i.e. one of the
|
134
|
+
# {http://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/notifications/cachelistener/annotation/package-summary.html
|
135
|
+
# Infinispan annotations}:
|
136
|
+
#
|
137
|
+
# - :cache_entries_evicted
|
138
|
+
# - :cache_entry_activated
|
139
|
+
# - :cache_entry_created
|
140
|
+
# - :cache_entry_invalidated
|
141
|
+
# - :cache_entry_loaded
|
142
|
+
# - :cache_entry_modified
|
143
|
+
# - :cache_entry_passivated
|
144
|
+
# - :cache_entry_removed
|
145
|
+
# - :cache_entry_visited
|
146
|
+
# - :data_rehashed
|
147
|
+
# - :topology_changed
|
148
|
+
# - :transaction_completed
|
149
|
+
# - :transaction_registered
|
150
|
+
#
|
151
|
+
# The callbacks are synchronous, i.e. invoked on the thread acting on
|
152
|
+
# the cache. For longer running callbacks, use a queue or some sort of
|
153
|
+
# asynchronous channel.
|
154
|
+
#
|
155
|
+
# The return value is an array of listener objects corresponding
|
156
|
+
# to the requested event types, which will be a subset of those
|
157
|
+
# returned from the {get_listeners} method. These may be passed
|
158
|
+
# to the {remove_listener} method to turn off notifications.
|
159
|
+
def add_listener(*types, &block)
|
160
|
+
handler = Handler.new(block)
|
161
|
+
listeners = types.map { |type| Listener::listen(handler, type.to_s) }
|
162
|
+
listeners.each { |listener| @cache.add_listener(listener) }
|
163
|
+
end
|
164
|
+
|
165
|
+
# @!method get(key)
|
166
|
+
#
|
167
|
+
# Get the value associated with the key
|
168
|
+
#
|
169
|
+
# @return [Object] nil if missing
|
170
|
+
def_delegators :@cache, :get
|
171
|
+
|
172
|
+
# @!method size()
|
173
|
+
#
|
174
|
+
# Get the number of entries in the cache
|
175
|
+
#
|
176
|
+
# @return [Fixnum]
|
177
|
+
def_delegators :@cache, :size
|
178
|
+
|
179
|
+
# @!method empty?()
|
180
|
+
#
|
181
|
+
# Return true if cache contains no entries
|
182
|
+
#
|
183
|
+
# @return [true, false]
|
184
|
+
def_delegators :@cache, :empty?
|
185
|
+
|
186
|
+
# @!method entry_set()
|
187
|
+
#
|
188
|
+
# Return a Set of Map.Entry instances
|
189
|
+
#
|
190
|
+
# @return [Set]
|
191
|
+
def_delegators :@cache, :entry_set
|
192
|
+
|
193
|
+
# @!method contains_key?(key)
|
194
|
+
#
|
195
|
+
# Return true if cache contains the key
|
196
|
+
#
|
197
|
+
# @return [true, false]
|
198
|
+
def_delegators :@cache, :contains_key?
|
199
|
+
|
200
|
+
# @!method evict(key)
|
201
|
+
#
|
202
|
+
# Remove entry from the heap, but not persistent storage, so
|
203
|
+
# subsequent reads will cause it to be reloaded
|
204
|
+
#
|
205
|
+
# @return [void]
|
206
|
+
def_delegators :@cache, :evict
|
207
|
+
|
208
|
+
# @!method remove(key)
|
209
|
+
#
|
210
|
+
# Remove the entry associated with the key
|
211
|
+
#
|
212
|
+
# @return [Object] the old value or nil, if key is missing
|
213
|
+
def_delegators :@cache, :remove
|
214
|
+
|
215
|
+
# @!method values()
|
216
|
+
#
|
217
|
+
# Get the values in the cache
|
218
|
+
#
|
219
|
+
# @return [Array]
|
220
|
+
def_delegators :@cache, :values
|
221
|
+
|
222
|
+
# @!method keys()
|
223
|
+
#
|
224
|
+
# Get the keys in the cache
|
225
|
+
#
|
226
|
+
# @return [Array]
|
227
|
+
def_delegators :@cache, :keys
|
228
|
+
|
229
|
+
# @!method name()
|
230
|
+
#
|
231
|
+
# Get cache name
|
232
|
+
#
|
233
|
+
# @return [String]
|
234
|
+
def_delegators :@cache, :name
|
235
|
+
|
236
|
+
# @!method get_listeners()
|
237
|
+
#
|
238
|
+
# Get the cache's active event listener instances
|
239
|
+
#
|
240
|
+
# @return [Array]
|
241
|
+
def_delegators :@cache, :get_listeners
|
242
|
+
|
243
|
+
# @!method remove_listener(listener)
|
244
|
+
#
|
245
|
+
# Turn off a particular event listener
|
246
|
+
#
|
247
|
+
# @return [void]
|
248
|
+
def_delegators :@cache, :remove_listener
|
249
|
+
|
250
|
+
# @!method configuration()
|
251
|
+
#
|
252
|
+
# Get the cache's configuration instance
|
253
|
+
#
|
254
|
+
# @return [org.infinispan.configuration.cache.Configuration]
|
255
|
+
def_delegator :@cache, :cache_configuration, :configuration
|
256
|
+
|
257
|
+
# @!method cache()
|
258
|
+
#
|
259
|
+
# Accessor for the wrapped cache instance
|
260
|
+
#
|
261
|
+
# @return [org.infinispan.Cache]
|
262
|
+
attr_accessor :cache
|
263
|
+
|
264
|
+
def_delegators :@cache, :[], :[]=
|
265
|
+
|
266
|
+
|
267
|
+
private
|
268
|
+
|
269
|
+
def defaults(options)
|
270
|
+
{ :ttl => -1, :idle => -1 }.merge(@options).merge(options)
|
271
|
+
end
|
272
|
+
|
273
|
+
def expiry(options)
|
274
|
+
m = defaults(options)
|
275
|
+
[m[:ttl], TimeUnit::MILLISECONDS, m[:idle], TimeUnit::MILLISECONDS]
|
276
|
+
end
|
277
|
+
|
278
|
+
class Handler
|
279
|
+
include Java::OrgProjectoddWunderbossCachingNotifications::Handler
|
280
|
+
def initialize(block)
|
281
|
+
@block = block
|
282
|
+
end
|
283
|
+
|
284
|
+
def handle(event)
|
285
|
+
@block.call(event)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def replace_m
|
290
|
+
@replace_m ||= @cache.java_method(:replace, [java.lang.Object,
|
291
|
+
java.lang.Object,
|
292
|
+
Java::long,
|
293
|
+
java.util.concurrent.TimeUnit,
|
294
|
+
Java::long,
|
295
|
+
java.util.concurrent.TimeUnit])
|
296
|
+
end
|
297
|
+
|
298
|
+
def cas_m
|
299
|
+
@cas_m ||= @cache.java_method(:replace, [java.lang.Object,
|
300
|
+
java.lang.Object,
|
301
|
+
java.lang.Object,
|
302
|
+
Java::long,
|
303
|
+
java.util.concurrent.TimeUnit,
|
304
|
+
Java::long,
|
305
|
+
java.util.concurrent.TimeUnit])
|
306
|
+
end
|
307
|
+
|
308
|
+
def put_m
|
309
|
+
@put_m ||= @cache.java_method(:put, [java.lang.Object,
|
310
|
+
java.lang.Object,
|
311
|
+
Java::long,
|
312
|
+
java.util.concurrent.TimeUnit,
|
313
|
+
Java::long,
|
314
|
+
java.util.concurrent.TimeUnit])
|
315
|
+
end
|
316
|
+
|
317
|
+
def putall_m
|
318
|
+
@putall_m ||= @cache.java_method(:putAll, [java.util.Map.java_class,
|
319
|
+
Java::long,
|
320
|
+
java.util.concurrent.TimeUnit,
|
321
|
+
Java::long,
|
322
|
+
java.util.concurrent.TimeUnit])
|
323
|
+
end
|
324
|
+
|
325
|
+
def putif_m
|
326
|
+
@putif_m ||= @cache.java_method(:putIfAbsent, [java.lang.Object,
|
327
|
+
java.lang.Object,
|
328
|
+
Java::long,
|
329
|
+
java.util.concurrent.TimeUnit,
|
330
|
+
Java::long,
|
331
|
+
java.util.concurrent.TimeUnit])
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# Copyright 2014 Red Hat, Inc, and individual contributors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'torquebox/codecs'
|
16
|
+
require 'torquebox/caching/cache'
|
17
|
+
|
18
|
+
module TorqueBox
|
19
|
+
module Caching
|
20
|
+
class << self
|
21
|
+
include OptionUtils
|
22
|
+
extend OptionUtils
|
23
|
+
java_import org.projectodd.wunderboss::WunderBoss
|
24
|
+
java_import org.projectodd.wunderboss::Options
|
25
|
+
java_import org.projectodd.wunderboss.caching::Caching
|
26
|
+
VALID_OPTIONS = optset(Caching::CreateOption, :encoding)
|
27
|
+
|
28
|
+
# Returns an
|
29
|
+
# {https://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/Cache.html
|
30
|
+
# org.infinispan.Cache}, an extension of
|
31
|
+
# `java.util.concurrent.ConcurrentMap`. A name is the only
|
32
|
+
# required argument. If a cache by that name already exists, it
|
33
|
+
# will be returned, and any options passed to this function will
|
34
|
+
# be ignored. To force reconfiguration of an existing cache,
|
35
|
+
# call {stop} before calling this function.
|
36
|
+
#
|
37
|
+
# *Durability:* Entries can persist to disk via the :persist
|
38
|
+
# option. If set to `true`, cache entries will persist in the
|
39
|
+
# current directory. Override this by setting `:persist` to a
|
40
|
+
# string naming the desired directory.
|
41
|
+
#
|
42
|
+
# *Eviction:* Turned off by default, `:max_entries` may be set to
|
43
|
+
# mitigate the risk of memory exhaustion. When `:persist` is
|
44
|
+
# enabled, evicted entries are written to disk, so that the
|
45
|
+
# entries in memory are a subset of those in the file store,
|
46
|
+
# transparently reloaded upon request. The eviction policy may
|
47
|
+
# be one of `:none`, `:lru`, `:lirs`, or `:unordered`
|
48
|
+
#
|
49
|
+
# *Expiration:* Both time-to-live and max idle limits are
|
50
|
+
# supported. Units are milliseconds.
|
51
|
+
#
|
52
|
+
# *Replication:* The replication mode defaults to `:dist_sync` when
|
53
|
+
# clustered. When not clustered, the value of `:mode` is ignored,
|
54
|
+
# and the cache will be `:local`. Asynchronous replication may
|
55
|
+
# yield a slight performance increase at the risk of potential
|
56
|
+
# cache inconsistency.
|
57
|
+
#
|
58
|
+
# *Transactions:* Caches can participate in transactions when a
|
59
|
+
# TransactionManager is available. The locking scheme may be
|
60
|
+
# either `:optimisitic` or `:pessimistic`
|
61
|
+
#
|
62
|
+
# *Advanced configuration:* Infinispan has many buttons,
|
63
|
+
# switches, dials, knobs and levers. Call the {builder} function
|
64
|
+
# to create your own Configuration instance and pass it in via
|
65
|
+
# the `:configuration` option.
|
66
|
+
#
|
67
|
+
# @param name [String] The name of the cache
|
68
|
+
# @param options [Hash] Options for cache creation.
|
69
|
+
# @option options :persist [String, true, false] (nil) if non-nil,
|
70
|
+
# data persists across server restarts in a file store; a
|
71
|
+
# string value names the directory
|
72
|
+
# @option options :max_entries [Number] (-1) the max number of
|
73
|
+
# entries allowed in the cache
|
74
|
+
# @option options :eviction [Symbol] (:none) how entries are
|
75
|
+
# evicted when :max_entries is exceeded
|
76
|
+
# @option options :ttl [Number] (-1) the max time the entry will
|
77
|
+
# live before expiry
|
78
|
+
# @option options :idle [Number] (-1) the time after which an
|
79
|
+
# entry will expire if not accessed
|
80
|
+
# @option options :mode [Symbol] (:dist_sync or :local)
|
81
|
+
# replication mode, one of :local, :repl_sync, :repl_async,
|
82
|
+
# :invalidation_sync, :invalidation_async, :dist_sync,
|
83
|
+
# :dist_async
|
84
|
+
# @option options :transactional [true, false] (false) whether
|
85
|
+
# the cache is transactional
|
86
|
+
# @option options :locking [Symbol] (:optimistic) transactional
|
87
|
+
# locking scheme
|
88
|
+
# @option options :encoding [Symbol] (:marshal_smart) other
|
89
|
+
# supported encodings include :edn, :json, :marshal,
|
90
|
+
# :marshal_base64 and :text
|
91
|
+
# @option options :configuration [Configuration] a
|
92
|
+
# {https://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/configuration/cache/Configuration.html
|
93
|
+
# Configuration} instance
|
94
|
+
# @return [Cache] The cache reference
|
95
|
+
def cache(name, options = {})
|
96
|
+
validate_options(options, VALID_OPTIONS)
|
97
|
+
cache = component.find_or_create(name, extract_options(options, Caching::CreateOption))
|
98
|
+
codec = Codecs[options.fetch(:encoding, :marshal_smart)]
|
99
|
+
Cache.new(component.withCodec(cache, codec), options)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Stop cache by name
|
103
|
+
#
|
104
|
+
# @param name [String] the name of the cache to stop
|
105
|
+
# @return [true, false] true if successfully stopped
|
106
|
+
def stop(name)
|
107
|
+
component.stop(name)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Determine whether cache is currently running
|
111
|
+
#
|
112
|
+
# @param name [String] the name of the cache
|
113
|
+
# @return [true, false] true if running
|
114
|
+
def exists?(name)
|
115
|
+
!!component.find(name)
|
116
|
+
end
|
117
|
+
|
118
|
+
# For advanced use, call this function to obtain a "fluent"
|
119
|
+
# {https://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/configuration/cache/ConfigurationBuilder.html
|
120
|
+
# ConfigurationBuilder}.
|
121
|
+
# Set the desired options, and invoke its build method, the
|
122
|
+
# result from which can be passed via the :configuration option
|
123
|
+
# of the {cache} function.
|
124
|
+
#
|
125
|
+
# Note that builder takes the same options as {cache}
|
126
|
+
def builder(options = {})
|
127
|
+
config = org.projectodd.wunderboss.caching::Config
|
128
|
+
config.builder(Options.new(extract_options(options, Caching::CreateOption)))
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def component
|
134
|
+
@component ||= WunderBoss.find_or_create_component(Caching.java_class)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright 2014 Red Hat, Inc, and individual contributors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'torquebox-core'
|
16
|
+
|
17
|
+
Dir.glob("#{File.dirname(__FILE__)}/wunderboss-jars/*.jar") do |jar|
|
18
|
+
TorqueBox::Jars.register_and_require(jar)
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'torquebox/caching'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torquebox-caching
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.0.0.alpha1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- The TorqueBox Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: torquebox-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0.alpha1
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 4.0.0.alpha1
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jbundler
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.14'
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
description:
|
84
|
+
email: torquebox-dev@torquebox.org
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- lib/torquebox-caching.rb
|
90
|
+
- lib/torquebox/caching.rb
|
91
|
+
- lib/torquebox/caching/cache.rb
|
92
|
+
- lib/active_support/cache/torquebox_store.rb
|
93
|
+
- lib/active_support/cache/torque_box_store.rb
|
94
|
+
- lib/wunderboss-jars/jboss-transaction-api_1.1_spec-1.0.1.Final.jar
|
95
|
+
- lib/wunderboss-jars/wunderboss-caching-1.x.incremental.174.jar
|
96
|
+
- lib/wunderboss-jars/infinispan-commons-6.0.2.Final.jar
|
97
|
+
- lib/wunderboss-jars/infinispan-core-6.0.2.Final.jar
|
98
|
+
- lib/wunderboss-jars/jboss-marshalling-river-1.4.4.Final.jar
|
99
|
+
- lib/wunderboss-jars/jboss-marshalling-1.4.4.Final.jar
|
100
|
+
homepage: http://torquebox.org/torqbox
|
101
|
+
licenses:
|
102
|
+
- Apache-2.0
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 1.9.3
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>'
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.1
|
118
|
+
requirements:
|
119
|
+
- jar org.projectodd.wunderboss:wunderboss-ruby, 1.x.incremental.174
|
120
|
+
- jar org.projectodd.wunderboss:wunderboss-caching, 1.x.incremental.174
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.1.9
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: TorqueBox Next Generation
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|