jruby-ehcache-rails2 1.2.0 → 1.3.0
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.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +15 -0
- data/History.txt +15 -0
- data/License.txt +23 -0
- data/Manifest.txt +37 -0
- data/PostInstall.txt +2 -0
- data/README.txt +9 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/config/ehcache.yml +22 -0
- data/config/ehcache_manual_rmi.yml +27 -0
- data/examples/ehcache.xml +44 -0
- data/examples/jruby-ehcache.rb +13 -0
- data/ext/ehcache-2.4.6/ehcache-core-2.4.6.jar +0 -0
- data/ext/ehcache-2.4.6/ehcache-terracotta-2.4.6.jar +0 -0
- data/ext/ehcache-2.4.6/slf4j-api-1.6.1.jar +0 -0
- data/ext/ehcache-2.4.6/slf4j-jdk14-1.6.1.jar +0 -0
- data/ext/ehcache-2.4.6/terracotta-toolkit-1.3-runtime-3.3.0.jar +0 -0
- data/ext/marshaled-ruby-object.jar +0 -0
- data/jruby-ehcache-rails2.gemspec +27 -0
- data/jruby-ehcache-rails3.gemspec +27 -0
- data/jruby-ehcache.gemspec +23 -0
- data/lib/ehcache.rb +22 -0
- data/lib/ehcache/active_support_store.rb +12 -1
- data/lib/ehcache/cache.rb +74 -0
- data/lib/ehcache/cache_manager.rb +69 -0
- data/lib/ehcache/config.rb +51 -0
- data/lib/ehcache/element.rb +36 -0
- data/lib/ehcache/java.rb +57 -0
- data/lib/ehcache/version.rb +3 -0
- data/lib/ehcache/yaml_config.rb +251 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/spec/cache_manager_spec.rb +81 -0
- data/spec/cache_spec.rb +86 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +12 -0
- data/src/net/sf/ehcache/MarshaledRubyObject.java +15 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/ehcache.xml +44 -0
- data/test/ehcache.yml +67 -0
- data/test/test_cache.rb +36 -0
- data/test/test_cache_manager.rb +27 -0
- data/test/test_configuration.rb +29 -0
- data/test/test_ehcache.rb +22 -0
- data/test/test_element.rb +37 -0
- data/test/test_helper.rb +22 -0
- data/test/test_yaml_config.rb +159 -0
- data/website/index.html +141 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +76 -97
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/History.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
== 0.0.3 2008-08-20
|
2
|
+
* 1 bug fix
|
3
|
+
* removed un-needed marshalling
|
4
|
+
* 1 major enhancement
|
5
|
+
* added support for configurable bootstrap cache loader and event listener
|
6
|
+
|
7
|
+
== 0.0.2 2008-06-08
|
8
|
+
|
9
|
+
* 1 bug fix
|
10
|
+
* add mutex, and marshalling for serialization to cache
|
11
|
+
|
12
|
+
== 0.0.1 2008-06-05
|
13
|
+
|
14
|
+
* 1 major enhancement:
|
15
|
+
* Initial release
|
data/License.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2008 - 2010 Dylan Stamat <dstamat@elctech.com> and
|
2
|
+
Jason Voegele <jason@jvoegele.com>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/ehcache
|
8
|
+
config/ehcache.yml
|
9
|
+
config/hoe.rb
|
10
|
+
config/requirements.rb
|
11
|
+
ext/ehcache-1.4.1/ehcache-1.4.1-remote-debugger.jar
|
12
|
+
ext/ehcache-1.4.1/ehcache-1.4.1.jar
|
13
|
+
ext/ehcache-1.4.1/lib/backport-util-concurrent-3.0.jar
|
14
|
+
ext/ehcache-1.4.1/lib/commons-logging-1.0.4.jar
|
15
|
+
ext/ehcache-1.4.1/lib/jsr107cache-1.0.jar
|
16
|
+
ext/rails/ehcache_store.rb
|
17
|
+
lib/ehcache.rb
|
18
|
+
lib/ehcache/cache.rb
|
19
|
+
lib/ehcache/cache_manager.rb
|
20
|
+
lib/ehcache/config.rb
|
21
|
+
lib/ehcache/element.rb
|
22
|
+
lib/ehcache/extensions.rb
|
23
|
+
lib/ehcache/java.rb
|
24
|
+
lib/ehcache/status.rb
|
25
|
+
lib/ehcache/version.rb
|
26
|
+
script/console
|
27
|
+
script/destroy
|
28
|
+
script/generate
|
29
|
+
script/txt2html
|
30
|
+
setup.rb
|
31
|
+
spec/spec_helper.rb
|
32
|
+
tasks/deployment.rake
|
33
|
+
tasks/environment.rake
|
34
|
+
tasks/website.rake
|
35
|
+
test/test_ehcache.rb
|
36
|
+
test/test_ehcachejr.rb
|
37
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.txt
CHANGED
@@ -51,6 +51,15 @@ OR
|
|
51
51
|
$ jruby -S gem install jruby-ehcache-rails3
|
52
52
|
|
53
53
|
|
54
|
+
== GEMFILE:
|
55
|
+
|
56
|
+
Add the gem as you normally would in your Gemfile, making sure to require
|
57
|
+
'ehcache' explicitly. Here is an example of adding the rails3 gem to a Gemfile.
|
58
|
+
|
59
|
+
gem 'jruby-ehcache-rails3', :require => 'ehcache'
|
60
|
+
|
61
|
+
|
62
|
+
|
54
63
|
== REQUIREMENTS:
|
55
64
|
|
56
65
|
Tested with JRuby 1.5.3.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_helper"
|
2
|
+
Bundler::GemHelper.install_tasks :name => "jruby-ehcache"
|
3
|
+
|
4
|
+
task :default => [ :test ]
|
5
|
+
|
6
|
+
require 'rdoc/task'
|
7
|
+
require 'rake/testtask'
|
8
|
+
desc "Executes the test suite"
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.name = :test
|
11
|
+
t.libs << 'lib' << 'ext' << 'test'
|
12
|
+
t.pattern = "test/test_*.rb"
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.0
|
data/config/ehcache.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
disk_store:
|
2
|
+
path: java.io.tmpdir
|
3
|
+
|
4
|
+
peer_providers:
|
5
|
+
- class: net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
|
6
|
+
properties: peerDiscovery=automatic,multicastGroupAddress=230.0.0.1,multicastGroupPort=4446,timeToLive=1
|
7
|
+
property_separator: "\,"
|
8
|
+
|
9
|
+
peer_listeners:
|
10
|
+
- class: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory
|
11
|
+
|
12
|
+
default_cache:
|
13
|
+
name: cache
|
14
|
+
max_elements_in_memory: 10000
|
15
|
+
time_to_live_seconds: 0
|
16
|
+
time_to_idle_seconds: 0
|
17
|
+
overflow_to_disk: true
|
18
|
+
eternal: false
|
19
|
+
disk_spool_buffer_size_mb: 30
|
20
|
+
disk_persistent: false
|
21
|
+
disk_expiry_thread_interval_seconds: 120
|
22
|
+
memory_store_eviction_policy: LRU
|
@@ -0,0 +1,27 @@
|
|
1
|
+
disk_store:
|
2
|
+
path: java.io.tmpdir
|
3
|
+
|
4
|
+
peer_providers:
|
5
|
+
- class: net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
|
6
|
+
properties: peerDiscovery=manual,rmiUrls=//that_hostname:40001/cache
|
7
|
+
property_separator: "\,"
|
8
|
+
|
9
|
+
peer_listeners:
|
10
|
+
- class: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory
|
11
|
+
properties: hostName=this_hostname,port=40000
|
12
|
+
|
13
|
+
default_cache:
|
14
|
+
name: cache
|
15
|
+
max_elements_in_memory: 10000
|
16
|
+
time_to_live_seconds: 0
|
17
|
+
time_to_idle_seconds: 0
|
18
|
+
overflow_to_disk: true
|
19
|
+
eternal: false
|
20
|
+
disk_spool_buffer_size_mb: 30
|
21
|
+
disk_persistent: false
|
22
|
+
disk_expiry_thread_interval_seconds: 120
|
23
|
+
memory_store_eviction_policy: LRU
|
24
|
+
event_listener: { class: net.sf.ehcache.distribution.RMICacheReplicatorFactory }
|
25
|
+
bootstrap_loader: { class: net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory,
|
26
|
+
properties: 'bootstrapAsynchronously=true,maximumChunkSizeBytes=5000000',
|
27
|
+
property_separator: "\," }
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
|
3
|
+
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd">
|
5
|
+
|
6
|
+
<!-- Disable for test ehcache.xml. Should go to the same place. -->
|
7
|
+
<diskStore path="java.io.tmpdir"/>
|
8
|
+
|
9
|
+
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
|
10
|
+
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=0"/>
|
11
|
+
|
12
|
+
|
13
|
+
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
|
14
|
+
properties="hostName=, port=, socketTimeoutMillis="/>
|
15
|
+
|
16
|
+
|
17
|
+
<defaultCache
|
18
|
+
name="default"
|
19
|
+
maxElementsInMemory="10"
|
20
|
+
eternal="false"
|
21
|
+
timeToIdleSeconds="5"
|
22
|
+
timeToLiveSeconds="10"
|
23
|
+
overflowToDisk="true"
|
24
|
+
/>
|
25
|
+
|
26
|
+
|
27
|
+
<!-- Sample cache named sampleCache1 -->
|
28
|
+
<cache name="sampleCache1"
|
29
|
+
maxElementsInMemory="10000"
|
30
|
+
maxElementsOnDisk="1000"
|
31
|
+
eternal="false"
|
32
|
+
timeToIdleSeconds="360"
|
33
|
+
timeToLiveSeconds="1000"
|
34
|
+
overflowToDisk="true">
|
35
|
+
</cache>
|
36
|
+
|
37
|
+
<!-- Sample cache named sampleCache2. Is eternal. Is diskPersistent but does not overflow to disk -->
|
38
|
+
<cache name="sampleCache2"
|
39
|
+
maxElementsInMemory="1000"
|
40
|
+
eternal="true"
|
41
|
+
overflowToDisk="false"
|
42
|
+
diskPersistent="true"
|
43
|
+
/>
|
44
|
+
</ehcache>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'ehcache'
|
2
|
+
|
3
|
+
manager = Ehcache::CacheManager.new
|
4
|
+
cache = manager.cache
|
5
|
+
|
6
|
+
cache.put("answer", "42", {:ttl => 120})
|
7
|
+
answer = cache.get("answer")
|
8
|
+
puts "Answer: #{answer}"
|
9
|
+
|
10
|
+
question = cache.get("question") || 'unknown'
|
11
|
+
puts "Question: #{question}"
|
12
|
+
|
13
|
+
manager.shutdown
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ehcache/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{jruby-ehcache-rails2}
|
7
|
+
s.version = Ehcache::VERSION
|
8
|
+
s.authors = [%q{Dylan Stamat}, %q{Jason Voegele}]
|
9
|
+
s.date = %q{2012-03-14}
|
10
|
+
s.description = %q{The Ehcache cache store provider for Rails 2}
|
11
|
+
s.email = [%q{dstamat@elctech.com}, %q{jvoegele@terracotta.org}]
|
12
|
+
s.extra_rdoc_files = [ "README.txt" ]
|
13
|
+
s.homepage = %q{http://ehcache.rubyforge.org}
|
14
|
+
s.rubyforge_project = %q{ehcache}
|
15
|
+
s.rubygems_version = %q{1.8.9}
|
16
|
+
s.summary = %q{Rails 2 cache store provider using Ehcache}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n").concat(
|
19
|
+
["lib/active_support/ehcache_store.rb",
|
20
|
+
"lib/ehcache/active_support_store.rb"])
|
21
|
+
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.add_runtime_dependency "jruby-ehcache"
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ehcache/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{jruby-ehcache-rails3}
|
7
|
+
s.version = Ehcache::VERSION
|
8
|
+
s.authors = [%q{Dylan Stamat}, %q{Jason Voegele}]
|
9
|
+
s.date = %q{2012-03-14}
|
10
|
+
s.description = %q{The Ehcache cache store provider for Rails 3}
|
11
|
+
s.email = [%q{dstamat@elctech.com}, %q{jvoegele@terracotta.org}]
|
12
|
+
s.extra_rdoc_files = [ "README.txt" ]
|
13
|
+
s.homepage = %q{http://ehcache.rubyforge.org}
|
14
|
+
s.rubyforge_project = %q{ehcache}
|
15
|
+
s.rubygems_version = %q{1.8.9}
|
16
|
+
s.summary = %q{Rails 3 cache store provider using Ehcache}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n").concat(
|
19
|
+
["lib/active_support/cache/ehcache_store.rb",
|
20
|
+
"lib/ehcache/active_support_store.rb"])
|
21
|
+
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.add_runtime_dependency "jruby-ehcache"
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ehcache/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{jruby-ehcache}
|
7
|
+
s.version = Ehcache::VERSION
|
8
|
+
s.authors = [%q{Dylan Stamat}, %q{Jason Voegele}]
|
9
|
+
s.date = %q{2012-03-14}
|
10
|
+
s.description = %q{JRuby interface to the popular Java caching library Ehcache}
|
11
|
+
s.email = [%q{dstamat@elctech.com}, %q{jvoegele@terracotta.org}]
|
12
|
+
s.extra_rdoc_files = [ "README.txt" ]
|
13
|
+
s.homepage = %q{http://ehcache.rubyforge.org}
|
14
|
+
s.rubyforge_project = %q{ehcache}
|
15
|
+
s.rubygems_version = %q{1.8.9}
|
16
|
+
s.summary = %q{JRuby interface to Ehcache}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
end
|
data/lib/ehcache.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
unless $:.include?(File.dirname(__FILE__)) ||
|
2
|
+
$:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
$:.unshift(File.dirname(__FILE__))
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'java'
|
7
|
+
|
8
|
+
module Ehcache
|
9
|
+
unless defined?(EHCACHE_HOME)
|
10
|
+
EHCACHE_HOME = File.expand_path(File.dirname(__FILE__) + '/..')
|
11
|
+
end
|
12
|
+
|
13
|
+
# wraps all native exceptions
|
14
|
+
class EhcacheError < RuntimeError; end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'ehcache/extensions'
|
18
|
+
require 'ehcache/java'
|
19
|
+
require 'ehcache/config'
|
20
|
+
require 'ehcache/cache'
|
21
|
+
require 'ehcache/cache_manager'
|
22
|
+
require 'ehcache/element'
|
@@ -44,4 +44,15 @@ module Ehcache
|
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if defined?(Rails)
|
50
|
+
Ehcache::ActiveSupportStore.default_cache_name = 'rails_cache'
|
51
|
+
|
52
|
+
case Rails::VERSION::MAJOR
|
53
|
+
when 2
|
54
|
+
Ehcache::ActiveSupportStore.config_directory = File.expand_path(File.join(RAILS_ROOT, 'config'))
|
55
|
+
when 3
|
56
|
+
Ehcache::ActiveSupportStore.config_directory = File.expand_path(File.join(::Rails.root, 'config'))
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Enhance net.sf.ehcache.Cache with a more Rubyesque API.
|
2
|
+
class Java::NetSfEhcache::Cache
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
# Yield each Element stored in this cache to the given block. This method
|
6
|
+
# uses Cache#getKeys as its basis, and therefore it is possible that some
|
7
|
+
# of the yielded elements have expired.
|
8
|
+
def each
|
9
|
+
for key in self.getKeys
|
10
|
+
yield self.get(key)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Does this cache require marshalling of Ruby objects?
|
15
|
+
def marshal?
|
16
|
+
config = self.cache_configuration
|
17
|
+
config.overflow_to_disk? || config.overflow_to_off_heap? || config.terracotta_clustered?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Gets an element value from the cache. Unlike the #get method, this method
|
21
|
+
# returns the element value, not the Element object.
|
22
|
+
def [](key)
|
23
|
+
element = self.get(key)
|
24
|
+
element ? element.value : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
alias ehcache_put put
|
28
|
+
|
29
|
+
# Wrap the Cache#put method to allow for extra options to be passed to the
|
30
|
+
# created Element.
|
31
|
+
def put(*args)
|
32
|
+
options = args.extract_options!
|
33
|
+
if args.size == 1 && args.first.kind_of?(Ehcache::Element)
|
34
|
+
element = args.first
|
35
|
+
elsif args.size == 2
|
36
|
+
if marshal?
|
37
|
+
value = Java::NetSfEhcache::MarshaledRubyObject.new(Marshal.dump(args[1]).to_java_bytes)
|
38
|
+
end
|
39
|
+
element = Ehcache::Element.create(args[0], value, options)
|
40
|
+
else
|
41
|
+
raise ArgumentError, "Must be Element object or key and value arguments"
|
42
|
+
end
|
43
|
+
|
44
|
+
if options[:unless_exist] || options[:unlessExist] ||
|
45
|
+
options[:if_absent] ||options[:ifAbsent]
|
46
|
+
put_if_absent(element)
|
47
|
+
else
|
48
|
+
ehcache_put(element)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
alias []= put
|
53
|
+
|
54
|
+
alias include? isKeyInCache
|
55
|
+
alias member? isKeyInCache
|
56
|
+
|
57
|
+
# Atomic compare and swap for cache elements. Invokes the given block with
|
58
|
+
# the current value of the element and attempts to replace it with the
|
59
|
+
# value returned from the block, repeating until replace returns true.
|
60
|
+
# Note that the provided block works only with element values, not Element
|
61
|
+
# objects: the result of element.getValue is passed to the block parameter,
|
62
|
+
# and the block is expected to return a value based on it.
|
63
|
+
# If there is no element with the given key, returns immediately without
|
64
|
+
# retrying.
|
65
|
+
def compare_and_swap(key, &block)
|
66
|
+
begin
|
67
|
+
old_element = self.get(key)
|
68
|
+
return nil unless old_element
|
69
|
+
new_element = Ehcache::Element.new(key, yield(old_element.value))
|
70
|
+
end until replace(old_element, new_element)
|
71
|
+
end
|
72
|
+
|
73
|
+
alias update compare_and_swap
|
74
|
+
end
|