jruby-ehcache 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/History.txt +15 -0
  2. data/License.txt +22 -0
  3. data/Manifest.txt +37 -0
  4. data/PostInstall.txt +2 -0
  5. data/README.txt +84 -0
  6. data/Rakefile +46 -0
  7. data/VERSION +1 -0
  8. data/bin/ehcache +28 -0
  9. data/config/ehcache.yml +22 -0
  10. data/config/ehcache_manual_rmi.yml +27 -0
  11. data/ext/ehcache-2.2.0/ehcache-core-2.2.0.jar +0 -0
  12. data/ext/ehcache-2.2.0/ehcache-terracotta-2.2.0.jar +0 -0
  13. data/ext/ehcache-2.2.0/slf4j-api-1.5.11.jar +0 -0
  14. data/ext/ehcache-2.2.0/slf4j-jdk14-1.5.11.jar +0 -0
  15. data/ext/ehcache-2.2.0/terracotta-toolkit-1.0-runtime-1.0.0.jar +0 -0
  16. data/lib/ehcache.rb +22 -0
  17. data/lib/ehcache/cache.rb +127 -0
  18. data/lib/ehcache/cache_manager.rb +65 -0
  19. data/lib/ehcache/config.rb +128 -0
  20. data/lib/ehcache/element.rb +27 -0
  21. data/lib/ehcache/extensions.rb +28 -0
  22. data/lib/ehcache/java.rb +8 -0
  23. data/lib/ehcache/status.rb +9 -0
  24. data/lib/ehcache/version.rb +9 -0
  25. data/script/console +10 -0
  26. data/script/destroy +14 -0
  27. data/script/generate +14 -0
  28. data/script/txt2html +82 -0
  29. data/setup.rb +1585 -0
  30. data/spec/cache_manager_spec.rb +81 -0
  31. data/spec/cache_spec.rb +86 -0
  32. data/spec/spec.opts +2 -0
  33. data/spec/spec_helper.rb +12 -0
  34. data/tasks/deployment.rake +34 -0
  35. data/tasks/environment.rake +7 -0
  36. data/tasks/website.rake +17 -0
  37. data/test/test_ehcache.rb +11 -0
  38. data/test/test_ehcachejr.rb +11 -0
  39. data/test/test_helper.rb +2 -0
  40. data/website/index.html +141 -0
  41. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  42. data/website/stylesheets/screen.css +138 -0
  43. data/website/template.html.erb +48 -0
  44. metadata +114 -0
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,22 @@
1
+ Copyright (c) 2008 Dylan Stamat
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ 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
@@ -0,0 +1,2 @@
1
+ For more information on this gem, and Ehcache proper, see:
2
+ http://github.com/dylanz/ehcache/tree/master/README.txt
data/README.txt ADDED
@@ -0,0 +1,84 @@
1
+ = Ehcache for JRuby
2
+
3
+ http://github.com/dylanz/ehcache
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ehcache is a simplified JRuby interface to Java's (JSR-107 compliant) Ehcache.
8
+ Simplified meaning that it should work out-of-the-box, but a lot of native
9
+ methods haven't been interfaced yet, as they weren't needed. Configuration
10
+ occurs in config/ehcache.yml, and should support all the configuration
11
+ options available.
12
+
13
+ Some biased and non-biased Ehcache VS Memcache articles:
14
+ http://gregluck.com/blog/archives/2007/05/comparing_memca.html
15
+ http://feedblog.org/2007/05/21/unfair-benchmarks-of-ehcache-vs-memcached
16
+ http://blog.aristotlesdog.com/2008/05/01/memcached_vs_ehcache/
17
+ http://www.hugotroche.com/my_weblog/2008/06/ehcache-vs-memc.html
18
+
19
+ For more information on Ehcache, see:
20
+ http://www.ehcache.org/
21
+
22
+ Configuration, Code Samples and everything else, see:
23
+ http://ehcache.org/documentation/index.html
24
+
25
+ Google Groups:
26
+ http://groups.google.com/group/ehcache-jruby
27
+
28
+ Tickets:
29
+ http://dylanz.lighthouseapp.com/projects/14518-ehcache-jruby/overview
30
+
31
+
32
+ == BASIC USAGE:
33
+
34
+ manager = CacheManager.new
35
+ cache = manager.cache
36
+ cache.put("key", "value", {:ttl => 120})
37
+ cache.get("key")
38
+ manager.shutdown
39
+
40
+
41
+ == RAILS:
42
+
43
+ Rails 2 and Rails 3 integration are provided by the separate ehcache-rails2
44
+ and ehcache-rails3 gems. To install, choose the correct version for your
45
+ Rails application and use JRuby's gem command to install, e.g.:
46
+
47
+ $ jgem install ehcache-rails3
48
+ OR
49
+ $ jruby -S gem install ehcache-rails3
50
+
51
+
52
+ == REQUIREMENTS:
53
+
54
+ Tested with JRuby 1.5.0.
55
+
56
+
57
+ == INSTALL:
58
+
59
+ $ sudo jruby -S gem install ehcache
60
+
61
+
62
+ == LICENSE:
63
+ Copyright (c) 2008 Dylan Stamat <dstamat@elctech.com>
64
+
65
+ Permission is hereby granted, free of charge, to any person
66
+ obtaining a copy of this software and associated documentation
67
+ files (the "Software"), to deal in the Software without
68
+ restriction, including without limitation the rights to use,
69
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
70
+ copies of the Software, and to permit persons to whom the
71
+ Software is furnished to do so, subject to the following
72
+ conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
78
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
79
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
80
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
81
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
82
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
83
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
84
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ begin
2
+ require 'jeweler'
3
+ rescue LoadError
4
+ puts "Jeweler not available. Install it with: gem install jeweler"
5
+ end
6
+
7
+ def defaults(gemspec)
8
+ gemspec.rubyforge_project = 'ehcache'
9
+ gemspec.homepage = "http://ehcache.rubyforge.org"
10
+ gemspec.authors = ["Dylan Stamat", "Jason Voegele"]
11
+ gemspec.email = ['dstamat@elctech.com', 'jvoegele@terracotta.org']
12
+ end
13
+
14
+ Jeweler::Tasks.new do |gemspec|
15
+ defaults(gemspec)
16
+ gemspec.name = "jruby-ehcache"
17
+ gemspec.summary = "JRuby interface to Ehcache"
18
+ gemspec.description = "JRuby interface to the popular Java caching library Ehcache"
19
+ gemspec.files.exclude '.gitignore'
20
+
21
+ # These files go in the ehcache-rails2 and ehcache-rails3 gems
22
+ gemspec.files.exclude 'lib/ehcache_store.rb'
23
+ gemspec.files.exclude 'lib/active_support/**/*'
24
+ end
25
+
26
+ Jeweler::Tasks.new do |gemspec|
27
+ defaults(gemspec)
28
+ gemspec.name = 'ehcache-rails3'
29
+ gemspec.summary = 'Rails 3 cache store provider using Ehcache'
30
+ gemspec.description = 'Rails 3 cache store provider using Ehcache'
31
+ gemspec.files = 'lib/active_support/**/*'
32
+ gemspec.test_files = []
33
+ gemspec.add_dependency 'jruby-ehcache', ">=0.5.0"
34
+ end
35
+
36
+ Jeweler::Tasks.new do |gemspec|
37
+ defaults(gemspec)
38
+ gemspec.name = 'ehcache-rails2'
39
+ gemspec.summary = 'Rails 2 cache store provider using Ehcache'
40
+ gemspec.description = 'Rails 2 cache store provider using Ehcache'
41
+ gemspec.files = 'lib/ehcache_store.rb'
42
+ gemspec.test_files = []
43
+ gemspec.add_dependency 'jruby-ehcache', ">=0.5.0"
44
+ end
45
+
46
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
data/bin/ehcache ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+ require 'rubygems'
5
+ require 'ehcache'
6
+
7
+ # TODO: optionparser this up once anything else is added
8
+ if $*.pop == "rails"
9
+ unless File.exists?("config/boot.rb")
10
+ abort "Oops... make sure you are running this from your RAILS_ROOT"
11
+ end
12
+
13
+ # copy default ehcache.yml into config/
14
+ if File.exists?("config/ehcache.yml")
15
+ warn "It looks like ehcache.yml already exists in config/"
16
+ else
17
+ FileUtils.cp("#{Ehcache::EHCACHE_HOME}/config/ehcache.yml", "config/")
18
+ end
19
+
20
+ # add ehcache store
21
+ if File.exists?("lib/ehcache_store.rb")
22
+ warn "It looks like ehcache_store.rb already exists in lib/"
23
+ else
24
+ FileUtils.cp("#{Ehcache::EHCACHE_HOME}/ext/rails/ehcache_store.rb", "lib/")
25
+ end
26
+ else
27
+ warn "Usage: specify 'rails' as an argument to install required files"
28
+ end
@@ -0,0 +1,22 @@
1
+ disk:
2
+ path: java.io.tmpdir
3
+
4
+ peer_provider:
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_listener:
10
+ class: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory
11
+
12
+ default:
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:
2
+ path: java.io.tmpdir
3
+
4
+ peer_provider:
5
+ class: net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
6
+ properties: peerDiscovery=manual,rmiUrls=//that_hostname:40001/cache
7
+ property_separator: "\,"
8
+
9
+ peer_listener:
10
+ class: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory
11
+ properties: hostName=this_hostname,port=40000
12
+
13
+ default:
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: "\," }
data/lib/ehcache.rb ADDED
@@ -0,0 +1,22 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'java'
5
+
6
+ module Ehcache
7
+ unless defined?(EHCACHE_HOME)
8
+ EHCACHE_HOME = File.expand_path(File.dirname(__FILE__) + '/..')
9
+ end
10
+
11
+ # wraps all native exceptions
12
+ class EhcacheError < RuntimeError; end
13
+ end
14
+
15
+ require 'ehcache/java'
16
+ require 'ehcache/config'
17
+ require 'ehcache/cache'
18
+ require 'ehcache/cache_manager'
19
+ require 'ehcache/element'
20
+ require 'ehcache/extensions'
21
+ require 'ehcache/version'
22
+ require 'ehcache/status'
@@ -0,0 +1,127 @@
1
+ module Ehcache
2
+ class Cache
3
+ PRIMARY = "cache"
4
+
5
+ # pull cache from given manager by name
6
+ def initialize(manager, cache_name)
7
+ @proxy = manager.get_cache(cache_name)
8
+ end
9
+
10
+ # put a new element into the cache
11
+ def put(key, value, options = {})
12
+ if key.nil? || key.empty?
13
+ raise EhcacheError, "Element cannot be blank"
14
+ end
15
+ element = Ehcache::Element.new(key, value, options)
16
+ @proxy.put(element.proxy)
17
+ rescue NativeException => e
18
+ raise EhcacheError, e.cause
19
+ end
20
+ alias_method :set, :put
21
+ alias_method :add, :put
22
+
23
+ # another alias for put
24
+ def []=(key, value)
25
+ put(key, value)
26
+ end
27
+
28
+ # get an element value from cache by key
29
+ def get(key)
30
+ element = @proxy.get(key)
31
+ element ? element.get_value : nil
32
+ rescue NativeException => e
33
+ raise EhcacheError, e.cause
34
+ end
35
+ alias_method :[], :get
36
+
37
+ # get an element from cache by key
38
+ def element(key)
39
+ element = @proxy.get(key)
40
+ return nil unless element
41
+ Ehcache::Element.new(element.get_key, element.get_value,
42
+ {:ttl => element.get_time_to_live })
43
+ rescue NativeException => e
44
+ raise EhcacheError, e.cause
45
+ end
46
+
47
+ # remove an element from the cache by key
48
+ def remove(key)
49
+ @proxy.remove(key)
50
+ rescue NativeException => e
51
+ raise EhcacheError, e.cause
52
+ end
53
+ alias_method :delete, :remove
54
+
55
+ # remove all elements from the cache
56
+ def remove_all
57
+ @proxy.remove_all
58
+ rescue NativeException => e
59
+ raise EhcacheError, e.cause
60
+ end
61
+ alias_method :clear, :remove_all
62
+
63
+ def keys
64
+ @proxy.get_keys
65
+ end
66
+
67
+ def exist?(key)
68
+ @proxy.is_key_in_cache(key)
69
+ end
70
+
71
+ # returns the current status of the cache
72
+ def status
73
+ @proxy.get_status
74
+ end
75
+
76
+ def alive?
77
+ @proxy.get_status == Status::ALIVE
78
+ end
79
+
80
+ def shutdown?
81
+ @proxy.get_status == Status::SHUTDOWN
82
+ end
83
+
84
+ def uninitialized?
85
+ @proxy.get_status == Status::UNINITIALISED
86
+ end
87
+
88
+ # number of elements in the cache
89
+ def size
90
+ @proxy.get_size
91
+ end
92
+
93
+ # number of elements in the memory store
94
+ def memory_size
95
+ @proxy.get_memory_store_size
96
+ end
97
+
98
+ # number of elements in the cache store
99
+ def disk_size
100
+ @proxy.get_disk_store_size
101
+ end
102
+
103
+ # TODO: implement statistics !
104
+ # return statistics about the cache
105
+ def statistics
106
+ @proxy.get_statistics
107
+ rescue NativeException => e
108
+ raise EhcacheError, e.cause
109
+ end
110
+
111
+ def max_elements
112
+ @proxy.get_max_elements_in_memory
113
+ end
114
+
115
+ def eternal?
116
+ @proxy.is_eternal
117
+ end
118
+
119
+ def ttl
120
+ @proxy.get_time_to_live_seconds
121
+ end
122
+
123
+ def tti
124
+ @proxy.get_time_to_idle_seconds
125
+ end
126
+ end
127
+ end