jruby-ehcache-rails3 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/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/lib/ehcache.rb +22 -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
|
|
@@ -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
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Enhance net.sf.ehcache.CacheManager with a more Rubyesque API.
|
|
2
|
+
class Java::NetSfEhcache::CacheManager
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
alias_method :ehcache_create, :create
|
|
7
|
+
|
|
8
|
+
# Enhanced create that provides for some extra configuration options.
|
|
9
|
+
# Specifically, String arguments may be used where native Ehcache expects
|
|
10
|
+
# java.io.File objects, and if the String refers to a YAML file it will be
|
|
11
|
+
# used as the Configuration source.
|
|
12
|
+
def create(*args)
|
|
13
|
+
process_init_args(*args) do |*args|
|
|
14
|
+
ehcache_create(*args)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Enhanced constructor that provides for some extra configuration options.
|
|
20
|
+
# Specifically, String arguments may be used where native Ehcache expects
|
|
21
|
+
# java.io.File objects, and if the String refers to a YAML file it will be
|
|
22
|
+
# used as the Configuration source.
|
|
23
|
+
def initialize(*args)
|
|
24
|
+
process_init_args(*args) do |*args|
|
|
25
|
+
super(*args)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Iterate through each cache managed by this CacheManager.
|
|
30
|
+
def each
|
|
31
|
+
for name in self.cache_names
|
|
32
|
+
yield self.get_ehcache(name)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
alias [] get_ehcache
|
|
37
|
+
|
|
38
|
+
def cache(cache_name = '__default_jruby_cache')
|
|
39
|
+
self.add_cache_if_absent(cache_name)
|
|
40
|
+
self.get_ehcache(cache_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# true if cache by given name is being managed, false otherwise
|
|
44
|
+
def include?(cache_name)
|
|
45
|
+
self.cache_exists(cache_name)
|
|
46
|
+
end
|
|
47
|
+
alias_method :exists?, :include?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Helper method for processing initialization arguments passed to
|
|
51
|
+
# CacheManager.create and CacheManager#initialize.
|
|
52
|
+
def process_init_args(*args)
|
|
53
|
+
args.compact!
|
|
54
|
+
if args.empty?
|
|
55
|
+
# First, look relative to the file that is creating the CacheManager.
|
|
56
|
+
# The expression caller[2] finds the entry in the call stack where
|
|
57
|
+
# CacheManager.new or CacheManager.create was called.
|
|
58
|
+
creator = /^(.+?):\d/.match(caller[2])[1]
|
|
59
|
+
if ehcache_config = Java::NetSfEhcacheConfig::Configuration.find(File.dirname(creator))
|
|
60
|
+
yield(ehcache_config)
|
|
61
|
+
else
|
|
62
|
+
yield
|
|
63
|
+
end
|
|
64
|
+
elsif args.size == 1 && args.first.is_a?(String)
|
|
65
|
+
yield(Ehcache::Config::Configuration.create(args.first))
|
|
66
|
+
else
|
|
67
|
+
yield(*args)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'ehcache/yaml_config'
|
|
2
|
+
|
|
3
|
+
# Enhance net.sf.ehcache.config.Configuration with a more Rubyesque API, and
|
|
4
|
+
# add support for using YAML for configuration.
|
|
5
|
+
class Java::NetSfEhcacheConfig::Configuration
|
|
6
|
+
Factory = Java::NetSfEhcacheConfig::ConfigurationFactory
|
|
7
|
+
|
|
8
|
+
# Searches for an Ehcache configuration file and, if found, returns a
|
|
9
|
+
# Configuration object created from it. The search algorithm looks for
|
|
10
|
+
# files named "ehcache.yml" or "ehcache.xml", first looking in the provided
|
|
11
|
+
# directories in order, and if not found there then looking in the Ruby
|
|
12
|
+
# $LOAD_PATH.
|
|
13
|
+
# Returns nil if no configuration file is found.
|
|
14
|
+
def self.find(*dirs)
|
|
15
|
+
file_names = %w[ehcache.yml ehcache.xml]
|
|
16
|
+
dirs += $LOAD_PATH
|
|
17
|
+
dirs.each do |dir|
|
|
18
|
+
file_names.each do |name|
|
|
19
|
+
candidate = File.join(dir, name)
|
|
20
|
+
return create(candidate) if File.exist?(candidate)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.create(*args)
|
|
27
|
+
result = nil
|
|
28
|
+
case args.size
|
|
29
|
+
when 0
|
|
30
|
+
result = Factory.parseConfiguration()
|
|
31
|
+
when 1
|
|
32
|
+
arg = args.first
|
|
33
|
+
|
|
34
|
+
if arg.is_a?(String)
|
|
35
|
+
raise ArgumentError, "Cannot read config file '#{arg}'" unless File.readable?(arg)
|
|
36
|
+
if arg =~ /\.yml$/
|
|
37
|
+
result = Ehcache::Config::YamlConfig.parse_yaml_config(arg)
|
|
38
|
+
else
|
|
39
|
+
result = Factory.parseConfiguration(java.io.File.new(arg))
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
result = Factory.parseConfiguration(arg)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
unless result.is_a?(self)
|
|
47
|
+
raise ArgumentError, "Could not create Configuration from: #{args.inspect}"
|
|
48
|
+
end
|
|
49
|
+
result
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Enhance net.sf.ehcache.Element with a more Rubyesque API.
|
|
2
|
+
class Java::NetSfEhcache::Element
|
|
3
|
+
def self.create(key, value, options = {})
|
|
4
|
+
result = self.new(key, value)
|
|
5
|
+
options.each do |key, value|
|
|
6
|
+
setter = "#{key}=".to_sym
|
|
7
|
+
result.send(setter, value) if result.respond_to?(setter)
|
|
8
|
+
end
|
|
9
|
+
result
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
alias element_value value
|
|
13
|
+
|
|
14
|
+
# Wrap the Element#value method to unmarshal Ruby objects if necessary.
|
|
15
|
+
def value
|
|
16
|
+
val = element_value
|
|
17
|
+
if val.kind_of?(Java::NetSfEhcache::MarshaledRubyObject)
|
|
18
|
+
Marshal.load(String.from_java_bytes(val.bytes))
|
|
19
|
+
else
|
|
20
|
+
val
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
alias tti getTimeToIdle
|
|
25
|
+
alias ttl getTimeToLive
|
|
26
|
+
|
|
27
|
+
alias tti= setTimeToIdle
|
|
28
|
+
alias ttl= setTimeToLive
|
|
29
|
+
|
|
30
|
+
alias expires_in getTimeToLive
|
|
31
|
+
def expires_in=(seconds)
|
|
32
|
+
setTimeToLive(seconds.to_i)
|
|
33
|
+
end
|
|
34
|
+
alias expiresIn expires_in
|
|
35
|
+
alias expiresIn= expires_in=
|
|
36
|
+
end
|
data/lib/ehcache/java.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'java'
|
|
2
|
+
|
|
3
|
+
EHCACHE_LIBS_DIR = "#{Ehcache::EHCACHE_HOME}/ext"
|
|
4
|
+
|
|
5
|
+
module Ehcache
|
|
6
|
+
module Rails
|
|
7
|
+
RAILS_ROOT_DIR = if defined?(::Rails)
|
|
8
|
+
::Rails.root.to_s
|
|
9
|
+
elsif defined?(RAILS_ROOT)
|
|
10
|
+
RAILS_ROOT
|
|
11
|
+
end
|
|
12
|
+
if RAILS_ROOT_DIR
|
|
13
|
+
RAILS_LIB_DIR = File.join(RAILS_ROOT_DIR, 'lib')
|
|
14
|
+
Dir["#{RAILS_LIB_DIR}/**/*.jar"].each do |jar|
|
|
15
|
+
$CLASSPATH << File.expand_path(jar)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
Dir["#{EHCACHE_LIBS_DIR}/**/*.jar"].each do |jar|
|
|
20
|
+
$CLASSPATH << File.expand_path(jar)
|
|
21
|
+
end
|
|
22
|
+
LOG = Java::OrgSlf4j::LoggerFactory.getLogger("JRubyEhcache")
|
|
23
|
+
LOG.info("Using Ehcache version #{Java::NetSfEhcacheUtil::ProductInfo.new.getVersion()}")
|
|
24
|
+
=begin
|
|
25
|
+
slf4j_loader = lambda { Java::OrgSlf4j::LoggerFactory.getLogger("JRubyEhcache") }
|
|
26
|
+
begin
|
|
27
|
+
LOG = slf4j_loader.call
|
|
28
|
+
LOG.info("Using SLF4J Logger from CLASSPATH")
|
|
29
|
+
rescue NameError
|
|
30
|
+
Dir["#{EHCACHE_LIBS_DIR}/**/*slf4j*.jar"].each do |l| require l end
|
|
31
|
+
LOG = slf4j_loader.call
|
|
32
|
+
LOG.info("Using bundled SLF4J Logger")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
ehcache_version_loader = lambda {
|
|
36
|
+
Java::NetSfEhcacheUtil::ProductInfo.new.getVersion()
|
|
37
|
+
}
|
|
38
|
+
begin
|
|
39
|
+
# If Ehcache is already on the classpath, use it.
|
|
40
|
+
VERSION = ehcache_version_loader.call
|
|
41
|
+
LOG.info("Using Ehcache #{VERSION} from CLASSPATH")
|
|
42
|
+
rescue NameError
|
|
43
|
+
# If not, use the Ehcache bundled with the jruby-ehcache gem.
|
|
44
|
+
Dir["#{EHCACHE_LIBS_DIR}/**/*.jar"].each do |l|
|
|
45
|
+
require l unless l =~ /slf4j/
|
|
46
|
+
end
|
|
47
|
+
VERSION = ehcache_version_loader.call
|
|
48
|
+
LOG.info("Using bundled Ehcache #{VERSION}")
|
|
49
|
+
end
|
|
50
|
+
=end
|
|
51
|
+
include_package 'net.sf.ehcache'
|
|
52
|
+
|
|
53
|
+
module Config
|
|
54
|
+
include_package 'net.sf.ehcache.config'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|