torquebox-cache 2.3.2-java → 3.0.0.beta1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,11 +59,11 @@ module ActiveSupport
59
59
 
60
60
  # Get the current entry
61
61
  key = namespaced_key( name, options )
62
- current = cache.get(key)
63
- value = decode(current).value.to_i
62
+ current = read_entry(key, options)
63
+ value = current.value.to_i
64
64
 
65
65
  new_entry = Entry.new( value+amount, options )
66
- if cache.replace( key, current, encode(new_entry) )
66
+ if cache.replace(key, current, new_entry)
67
67
  return new_entry.value
68
68
  else
69
69
  raise "Concurrent modification, old value was #{value}"
@@ -90,14 +90,6 @@ module ActiveSupport
90
90
  {:name=>'__torque_box_store__', :mode => :invalidation, :sync => false}
91
91
  end
92
92
 
93
- def encode value
94
- Marshal.dump(value).to_java_bytes
95
- end
96
-
97
- def decode value
98
- value && Marshal.load(String.from_java_bytes(value))
99
- end
100
-
101
93
  # Return the keys in the cache; potentially very expensive depending on configuration
102
94
  def keys
103
95
  cache.keys
@@ -105,12 +97,13 @@ module ActiveSupport
105
97
 
106
98
  # Read an entry from the cache implementation. Subclasses must implement this method.
107
99
  def read_entry(key, options)
108
- decode( cache.get( key ) )
100
+ cache.get( key )
109
101
  end
110
102
 
111
103
  # Write an entry to the cache implementation. Subclasses must implement this method.
112
104
  def write_entry(key, entry, options = {})
113
- options[:unless_exist] ? cache.put_if_absent( key, encode(entry) ) : cache.put( key, encode(entry) )
105
+ previous_value = options[:unless_exist] ? cache.put_if_absent( key, entry ) : cache.put( key, entry )
106
+ previous_value unless previous_value.nil?
114
107
  end
115
108
 
116
109
  # Delete an entry from the cache implementation. Subclasses must implement this method.
@@ -127,4 +120,3 @@ module ActiveSupport
127
120
  end
128
121
  end
129
122
  end
130
-
@@ -0,0 +1,2 @@
1
+ # This assignment allows :torquebox_store to work as a symbol
2
+ ActiveSupport::Cache::TorqueboxStore = ActiveSupport::Cache::TorqueBoxStore
data/lib/cache.rb CHANGED
@@ -18,14 +18,13 @@
18
18
  require 'torquebox/kernel'
19
19
  require 'torquebox/injectors'
20
20
  require 'torquebox/transactions'
21
- require 'sequence'
21
+ require 'torquebox/codecs'
22
22
 
23
23
  module TorqueBox
24
24
  module Infinispan
25
25
 
26
26
  # @api private
27
27
  class ContainerTransactionManagerLookup
28
- include TorqueBox::Injectors
29
28
  begin
30
29
  include org.infinispan.transaction.lookup.TransactionManagerLookup
31
30
  rescue NameError
@@ -33,22 +32,11 @@ module TorqueBox
33
32
  end
34
33
 
35
34
  def getTransactionManager
36
- fetch('transaction-manager')
37
- end
38
- end
39
-
40
- class NoOpCodec
41
- def self.encode(object)
42
- object
43
- end
44
-
45
- def self.decode(object)
46
- object
35
+ TorqueBox.fetch('transaction-manager')
47
36
  end
48
37
  end
49
38
 
50
39
  class Cache
51
- include TorqueBox::Injectors
52
40
 
53
41
  SECONDS = java.util.concurrent.TimeUnit::SECONDS
54
42
  begin
@@ -56,6 +44,7 @@ module TorqueBox
56
44
  java_import org.infinispan.configuration.cache::ConfigurationBuilder
57
45
  java_import org.infinispan.transaction::TransactionMode
58
46
  java_import org.infinispan.transaction::LockingMode
47
+ java_import org.infinispan.eviction::EvictionStrategy
59
48
  java_import org.projectodd.polyglot.cache.as::CacheService
60
49
  INFINISPAN_AVAILABLE = true
61
50
  rescue NameError => e
@@ -69,6 +58,13 @@ module TorqueBox
69
58
  options[:transaction_mode] = :transactional unless options.has_key?( :transaction_mode )
70
59
  options[:locking_mode] ||= :optimistic if (transactional? && !options.has_key?( :locking_mode ))
71
60
  options[:sync] = true if options[:sync].nil?
61
+ if options[:encoding] == :marshal
62
+ log( "Encoding of :marshal cannot be used with " +
63
+ "TorqueBox::Infinispan::Cache - using :marshal_base64 instead",
64
+ 'WARN')
65
+ options[:encoding] = :marshal_base64
66
+ end
67
+ @codec = TorqueBox::Codecs[ options[:encoding] || :marshal_smart ]
72
68
  cache
73
69
  end
74
70
 
@@ -77,7 +73,7 @@ module TorqueBox
77
73
  end
78
74
 
79
75
  def persisted?
80
- !options[:persist].nil?
76
+ !!options[:persist]
81
77
  end
82
78
 
83
79
  def replicated?
@@ -126,77 +122,82 @@ module TorqueBox
126
122
  transaction_mode == TransactionMode::TRANSACTIONAL
127
123
  end
128
124
 
125
+ def eviction_strategy
126
+ case options[:eviction]
127
+ when :lirs then EvictionStrategy::LIRS
128
+ when :lru then EvictionStrategy::LRU
129
+ when :unordered then EvictionStrategy::UNORDERED
130
+ end
131
+ end
132
+
133
+ def max_entries
134
+ options[:max_entries] || -1
135
+ end
136
+
129
137
  # Clear the entire cache. Be careful with this method since it could
130
138
  # affect other processes if shared cache is being used.
131
139
  def clear
132
- cache.clearAsync
140
+ cache.clear
133
141
  end
134
142
 
135
143
  # Return the keys in the cache; potentially very expensive depending on configuration
136
144
  def keys
137
- cache.key_set
145
+ cache.key_set.map{|k| decode(k)}
146
+ end
147
+
148
+ def size
149
+ cache.size
138
150
  end
139
151
 
140
152
  def all
141
- cache.key_set.collect{|k| get(k)}
153
+ keys.map{|k| get(k)}
142
154
  end
155
+ alias_method :values, :all
143
156
 
144
157
  def contains_key?( key )
145
- cache.contains_key( key.to_s )
158
+ cache.contains_key( encode(key) )
146
159
  end
147
160
 
148
161
  # Get an entry from the cache
149
162
  def get(key)
150
- cache.get( key.to_s )
163
+ decode(cache.get(encode(key)))
151
164
  end
165
+ alias_method :[], :get
152
166
 
153
167
  # Write an entry to the cache
154
168
  def put(key, value, expires = 0)
155
- __put(key, value, expires, :put_async)
169
+ __put(key, value, expires, :put)
156
170
  end
171
+ alias_method :[]=, :put
157
172
 
158
173
  def put_if_absent(key, value, expires = 0)
159
- __put(key, value, expires, :put_if_absent_async)
174
+ __put(key, value, expires, :put_if_absent)
160
175
  end
161
176
 
162
177
  def evict( key )
163
- cache.evict( key.to_s )
178
+ cache.evict( encode(key) )
164
179
  end
165
180
 
166
- def replace(key, original_value, new_value, codec=NoOpCodec)
167
- # First, grab the raw value from the cache, which is a byte[]
168
-
169
- current = get( key )
170
- decoded = codec.decode( current )
171
-
172
- # great! we've got a byte[] now. Let's apply == to it, like Jim says will work always
173
-
174
- if ( decoded == original_value )
175
- # how does this work?
176
- cache.replace( key.to_s, current, codec.encode( new_value ) )
177
- end
181
+ def replace(key, original_value, new_value)
182
+ cache.replace(encode(key), encode(original_value), encode(new_value))
178
183
  end
179
184
 
180
- # Delete an entry from the cache
185
+ # Delete an entry from the cache
181
186
  def remove(key)
182
- cache.removeAsync( key.to_s ) && true
187
+ decode(cache.remove(encode(key)))
183
188
  end
184
189
 
185
- def increment( sequence_name, amount = 1 )
186
- current_entry = Sequence::Codec.decode( get( sequence_name ) )
187
-
188
- # If we can't find the sequence in the cache, create a new one and return
189
- put( sequence_name, Sequence::Codec.encode( Sequence.new( amount ) ) ) and return amount if current_entry.nil?
190
-
191
- # Increment the sequence, stash it, and return
192
- next_entry = current_entry.next( amount )
193
-
194
- # Since replace() doesn't encode, let's encode everything to a byte[] for it, no?
195
- if replace( sequence_name, current_entry, next_entry, Sequence::Codec )
196
- return next_entry.value
190
+ def increment(sequence_name, amount = 1)
191
+ result, current = amount, get(sequence_name)
192
+ if current.nil?
193
+ put(sequence_name, result)
197
194
  else
198
- raise "Concurrent modification, old value was #{current_entry.value} new value #{next_entry.value}"
195
+ result = current + amount
196
+ unless replace(sequence_name, current, result)
197
+ raise "Concurrent modification, old value was #{current} new value #{result}"
198
+ end
199
199
  end
200
+ result
200
201
  end
201
202
 
202
203
  # Decrement an integer value in the cache; return new value
@@ -207,7 +208,7 @@ module TorqueBox
207
208
  def transaction(&block)
208
209
  if !transactional?
209
210
  yield self
210
- elsif fetch('transaction-manager').nil?
211
+ elsif TorqueBox.fetch('transaction-manager').nil?
211
212
  tm = cache.getAdvancedCache.getTransactionManager
212
213
  begin
213
214
  tm.begin if tm
@@ -255,6 +256,14 @@ module TorqueBox
255
256
 
256
257
  private
257
258
 
259
+ def encode(data)
260
+ @codec.encode(data)
261
+ end
262
+
263
+ def decode(data)
264
+ @codec.decode(data)
265
+ end
266
+
258
267
  def options
259
268
  @options ||= {}
260
269
  end
@@ -278,17 +287,23 @@ module TorqueBox
278
287
  def reconfigure(mode=clustering_mode)
279
288
  existing_cache = manager.get_cache(name)
280
289
  base_config = existing_cache.cache_configuration
281
- unless base_config.clustering.cache_mode == mode
282
- log( "Reconfiguring Infinispan cache #{name} from #{base_config.cache_mode} to #{mode}" )
290
+ new_config = configuration(mode)
291
+ unless same_config?(base_config, new_config)
292
+ log("Reconfiguring Infinispan cache #{name}")
283
293
  existing_cache.stop
284
- configure(mode)
294
+ manager.define_configuration(name, new_config )
285
295
  existing_cache.start
286
296
  end
287
297
  return existing_cache
288
298
  end
289
299
 
290
300
  def configure(mode=clustering_mode)
291
- log( "Configuring Infinispan cache #{name} as #{mode}" )
301
+ log( "Configuring Infinispan cache #{name}" )
302
+ manager.define_configuration(name, configuration(mode) )
303
+ manager.get_cache(name)
304
+ end
305
+
306
+ def configuration(mode=clustering_mode)
292
307
  config = ConfigurationBuilder.new.read( manager.default_cache_configuration )
293
308
  config.clustering.cacheMode( mode )
294
309
  config.transaction.transactionMode( transaction_mode )
@@ -301,19 +316,34 @@ module TorqueBox
301
316
  store.purgeOnStartup( false )
302
317
  store.location(options[:persist]) if File.exist?( options[:persist].to_s )
303
318
  end
304
- manager.define_configuration(name, config.build )
305
- manager.get_cache(name)
319
+ if ( options[:max_entries] )
320
+ config.eviction.max_entries( options[:max_entries] )
321
+ if ( options[:eviction] )
322
+ config.eviction.strategy( eviction_strategy )
323
+ end
324
+ end
325
+ config.build
306
326
  end
307
327
 
328
+ def same_config?(c1, c2)
329
+ c1.clustering.cacheMode == c2.clustering.cacheMode &&
330
+ (c1.loaders == c2.loaders ||
331
+ (c1.loaders.cacheLoaders.size == c2.loaders.cacheLoaders.size &&
332
+ c1.loaders.cacheLoaders.first.location == c2.loaders.cacheLoaders.first.location)) &&
333
+ c1.transaction.transactionMode == c2.transaction.transactionMode &&
334
+ c1.transaction.lockingMode == c2.transaction.lockingMode &&
335
+ c1.eviction.max_entries == c2.eviction.max_entries &&
336
+ c1.eviction.strategy == c2.eviction.strategy
337
+ end
338
+
308
339
  def transaction_manager_lookup
309
- @tm ||= if fetch('transaction-manager')
340
+ @tm ||= if TorqueBox.fetch('transaction-manager')
310
341
  ContainerTransactionManagerLookup.new
311
342
  else
312
343
  org.infinispan.transaction.lookup.GenericTransactionManagerLookup.new
313
344
  end
314
345
  end
315
346
 
316
-
317
347
  def nothing
318
348
  result = Object.new
319
349
  def result.method_missing(*args); end
@@ -322,7 +352,8 @@ module TorqueBox
322
352
  end
323
353
 
324
354
  def __put(key, value, expires, operation)
325
- args = [ operation, key.to_s, value ]
355
+ # encode
356
+ args = [ operation, encode(key), encode(value) ]
326
357
  if expires > 0
327
358
  # Set the Infinispan expire a few minutes into the future to support
328
359
  # :race_condition_ttl on read
@@ -331,7 +362,7 @@ module TorqueBox
331
362
  args << expires_in << SECONDS
332
363
  args << expires << SECONDS
333
364
  end
334
- cache.send( *args ) && true
365
+ decode(cache.send(*args))
335
366
  end
336
367
 
337
368
  end
data/lib/gem_hook.rb CHANGED
@@ -19,6 +19,7 @@ require 'cache'
19
19
  begin
20
20
  ActiveSupport
21
21
  require 'active_support/cache/torque_box_store.rb'
22
+ require 'active_support/cache/torquebox_store.rb'
22
23
  rescue NameError
23
24
  # ActiveSupport not used
24
25
  end
Binary file
@@ -1,11 +1,11 @@
1
1
  module TorqueboxCache
2
- VERSION = '2.3.2'
3
- MAVEN_VERSION = '2.3.2'
2
+ VERSION = '3.0.0.beta1'
3
+ MAVEN_VERSION = '3.0.0.beta1'
4
4
  end
5
5
  begin
6
6
  require 'java'
7
7
  require File.dirname(__FILE__) + '/torquebox-cache.jar'
8
- require File.dirname(__FILE__) + '/polyglot-cache-1.12.2.jar'
8
+ require File.dirname(__FILE__) + '/polyglot-cache-1.14.0.jar'
9
9
  rescue LoadError
10
10
  puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'
11
11
  raise
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
@@ -19,15 +19,17 @@ require 'cache_listener'
19
19
 
20
20
  describe TorqueBox::Infinispan::CacheListener do
21
21
  before :each do
22
- manager = org.infinispan.manager.DefaultCacheManager.new
22
+ @manager = org.infinispan.manager.DefaultCacheManager.new
23
23
  service = org.projectodd.polyglot.cache.as.CacheService.new
24
- service.stub!(:cache_container).and_return( manager )
24
+ service.stub!(:cache_container).and_return( @manager )
25
+ TorqueBox::Registry.merge!("transaction-manager" => nil)
25
26
  TorqueBox::ServiceRegistry.stub!(:[]).with(org.projectodd.polyglot.cache.as.CacheService::CACHE).and_return( service )
26
27
  @cache = TorqueBox::Infinispan::Cache.new( :name => 'foo-cache' )
27
28
  end
28
29
 
29
30
  after :each do
30
31
  @cache.clear
32
+ @manager.stop
31
33
  end
32
34
 
33
35
  it "the cache should accept listeners" do
data/spec/cache_spec.rb CHANGED
@@ -18,15 +18,17 @@ require File.dirname(__FILE__) + '/spec_helper'
18
18
 
19
19
  describe TorqueBox::Infinispan::Cache do
20
20
  before :each do
21
- manager = org.infinispan.manager.DefaultCacheManager.new
21
+ @manager = org.infinispan.manager.DefaultCacheManager.new
22
22
  service = org.projectodd.polyglot.cache.as.CacheService.new
23
- service.stub!(:cache_container).and_return( manager )
23
+ service.stub!(:cache_container).and_return( @manager )
24
+ TorqueBox::Registry.merge!("transaction-manager" => nil)
24
25
  TorqueBox::ServiceRegistry.stub!(:[]).with(org.projectodd.polyglot.cache.as.CacheService::CACHE).and_return( service )
25
26
  @cache = TorqueBox::Infinispan::Cache.new( :name => 'foo-cache' )
26
27
  end
27
28
 
28
29
  after :each do
29
30
  @cache.clear
31
+ @manager.stop
30
32
  end
31
33
 
32
34
  it "should have a name" do
@@ -34,17 +36,35 @@ describe TorqueBox::Infinispan::Cache do
34
36
  end
35
37
 
36
38
  it "should respond to clustering_mode" do
37
- @cache.should respond_to( :clustering_mode )
39
+ @cache.should respond_to( :clustering_mode )
40
+ end
41
+
42
+ it "should respond to eviction_strategy" do
43
+ @cache.should respond_to( :eviction_strategy )
44
+ end
45
+
46
+ it "should have a size" do
47
+ @cache.clear
48
+ @cache.size.should == 0
49
+ @cache.put('foo', 'bar');
50
+ @cache.size.should == 1
38
51
  end
39
52
 
40
53
  it "should accept and return strings" do
41
- @cache.put('foo', 'bar').should be_true
54
+ @cache.put('foo', 'bar').should be_nil
42
55
  @cache.get('foo').should == 'bar'
43
56
  end
44
57
 
58
+ it "should work with index operators" do
59
+ @cache[:a] = 1
60
+ @cache[:a].should == 1
61
+ @cache[:b] = "two"
62
+ @cache[:b].should == "two"
63
+ end
64
+
45
65
  it "should accept and return ruby objects" do
46
66
  heffalump = Snuffleuffagus.new(100, 'snuffle')
47
- @cache.put('heffalump', heffalump).should be_true
67
+ @cache.put('heffalump', heffalump).should be_nil
48
68
  rheffalump = @cache.get('heffalump')
49
69
  rheffalump.name.should == heffalump.name
50
70
  rheffalump.id.should == heffalump.id
@@ -61,6 +81,14 @@ describe TorqueBox::Infinispan::Cache do
61
81
  keys.include?('three').should be_true
62
82
  end
63
83
 
84
+ it "should return all values" do
85
+ @cache.put(:a, 1)
86
+ @cache.put(:b, 2)
87
+ @cache.put(:c, 3)
88
+ @cache.all.sort.should eql([1, 2, 3])
89
+ @cache.values.sort.should eql([1, 2, 3])
90
+ end
91
+
64
92
  it "should allow removal of a key/value" do
65
93
  @cache.put('foo', 'bar')
66
94
  @cache.keys.length.should == 1
@@ -69,13 +97,13 @@ describe TorqueBox::Infinispan::Cache do
69
97
  end
70
98
 
71
99
  it "should only insert on put_if_absent if the key is not already in the cache" do
72
- @cache.put_if_absent('foo', 'bar').should be_true
73
- @cache.put_if_absent('foo', 'foobar')
100
+ @cache.put_if_absent('foo', 'bar').should be_nil
101
+ @cache.put_if_absent('foo', 'foobar').should == 'bar'
74
102
  @cache.get('foo').should == 'bar'
75
103
  end
76
104
 
77
105
  it "should clear" do
78
- @cache.clear.should be_true
106
+ @cache.clear.should be_nil
79
107
  end
80
108
 
81
109
  it "should replace existing string values" do
@@ -153,7 +181,7 @@ describe TorqueBox::Infinispan::Cache do
153
181
 
154
182
  it "should allow symbols as keys for increment" do
155
183
  @cache.increment :countsymbol
156
- @cache.get(:countsymbol).should == "1"
184
+ @cache.get(:countsymbol).should == 1
157
185
  @cache.increment(:countsymbol).should == 2
158
186
  end
159
187
 
@@ -290,7 +318,7 @@ describe TorqueBox::Infinispan::Cache do
290
318
  it "should persist dates with a configured directory" do
291
319
  cache = TorqueBox::Infinispan::Cache.new( :name => 'persisted-configured-date-cache', :persist => @date_cfg_dir.to_s )
292
320
  entry = java.util.Date.new
293
- cache.put('foo', entry).should be_true
321
+ cache.put('foo', entry).should be_nil
294
322
  File.exist?("#{@date_cfg_dir.to_s}/persisted-configured-date-cache").should be_true
295
323
  end
296
324