jruby-ehcache-rails2 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +15 -0
  4. data/History.txt +15 -0
  5. data/License.txt +23 -0
  6. data/Manifest.txt +37 -0
  7. data/PostInstall.txt +2 -0
  8. data/README.txt +9 -0
  9. data/Rakefile +13 -0
  10. data/VERSION +1 -0
  11. data/config/ehcache.yml +22 -0
  12. data/config/ehcache_manual_rmi.yml +27 -0
  13. data/examples/ehcache.xml +44 -0
  14. data/examples/jruby-ehcache.rb +13 -0
  15. data/ext/ehcache-2.4.6/ehcache-core-2.4.6.jar +0 -0
  16. data/ext/ehcache-2.4.6/ehcache-terracotta-2.4.6.jar +0 -0
  17. data/ext/ehcache-2.4.6/slf4j-api-1.6.1.jar +0 -0
  18. data/ext/ehcache-2.4.6/slf4j-jdk14-1.6.1.jar +0 -0
  19. data/ext/ehcache-2.4.6/terracotta-toolkit-1.3-runtime-3.3.0.jar +0 -0
  20. data/ext/marshaled-ruby-object.jar +0 -0
  21. data/jruby-ehcache-rails2.gemspec +27 -0
  22. data/jruby-ehcache-rails3.gemspec +27 -0
  23. data/jruby-ehcache.gemspec +23 -0
  24. data/lib/ehcache.rb +22 -0
  25. data/lib/ehcache/active_support_store.rb +12 -1
  26. data/lib/ehcache/cache.rb +74 -0
  27. data/lib/ehcache/cache_manager.rb +69 -0
  28. data/lib/ehcache/config.rb +51 -0
  29. data/lib/ehcache/element.rb +36 -0
  30. data/lib/ehcache/java.rb +57 -0
  31. data/lib/ehcache/version.rb +3 -0
  32. data/lib/ehcache/yaml_config.rb +251 -0
  33. data/script/console +10 -0
  34. data/script/destroy +14 -0
  35. data/script/generate +14 -0
  36. data/script/txt2html +82 -0
  37. data/spec/cache_manager_spec.rb +81 -0
  38. data/spec/cache_spec.rb +86 -0
  39. data/spec/spec.opts +2 -0
  40. data/spec/spec_helper.rb +12 -0
  41. data/src/net/sf/ehcache/MarshaledRubyObject.java +15 -0
  42. data/tasks/deployment.rake +34 -0
  43. data/tasks/environment.rake +7 -0
  44. data/tasks/website.rake +17 -0
  45. data/test/ehcache.xml +44 -0
  46. data/test/ehcache.yml +67 -0
  47. data/test/test_cache.rb +36 -0
  48. data/test/test_cache_manager.rb +27 -0
  49. data/test/test_configuration.rb +29 -0
  50. data/test/test_ehcache.rb +22 -0
  51. data/test/test_element.rb +37 -0
  52. data/test/test_helper.rb +22 -0
  53. data/test/test_yaml_config.rb +159 -0
  54. data/website/index.html +141 -0
  55. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  56. data/website/stylesheets/screen.css +138 -0
  57. data/website/template.html.erb +48 -0
  58. metadata +76 -97
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/ehcache.rb'}"
9
+ puts "Loading ehcache gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'ehcache' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'ehcache'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
+
20
+ version = Ehcache::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)
@@ -0,0 +1,81 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe CacheManager do
4
+ before(:each) do
5
+ @manager = Ehcache::CacheManager.new
6
+ end
7
+
8
+ after(:each) do
9
+ @manager.shutdown
10
+ end
11
+ it "should return false if include? is called with a non-existant cache name" do
12
+ @manager.include?("zomg").should == false
13
+ end
14
+
15
+ it "should return false if exists? is called with a non-existant cache name" do
16
+ @manager.exists?("zomg").should == false
17
+ end
18
+
19
+ it "should return true if include? is called with an existant cache name" do
20
+ @manager.include?(Ehcache::Cache::PRIMARY).should == true
21
+ end
22
+
23
+ it "should return true if exists? is called with an existant cache name" do
24
+ @manager.exists?(Ehcache::Cache::PRIMARY).should == true
25
+ end
26
+
27
+ it "should return all the cache names when caches is called" do
28
+ @manager.caches.length.should == 1
29
+ end
30
+
31
+ it "should remove the cache when remove is called with a cache name" do
32
+ @manager.remove(Ehcache::Cache::PRIMARY)
33
+ @manager.caches.length.should == 0
34
+ end
35
+
36
+ it "should remove all the caches when remove_all is called" do
37
+ @manager.add_cache("mynewcache")
38
+ @manager.caches.length.should == 2
39
+ @manager.remove_all
40
+ @manager.caches.length.should == 0
41
+ end
42
+
43
+ it "should add a cache when cache is called with a cache name" do
44
+ @manager.add_cache("mynewcache")
45
+ @manager.caches.length.should == 2
46
+ end
47
+
48
+ it "should add a cache when cache is called with a cache name" do
49
+ cache = @manager.cache(Ehcache::Cache::PRIMARY)
50
+ cache.put("key", "value")
51
+ cache.get("key").should == "value"
52
+ @manager.flush_all
53
+ cache.get("key").should == nil
54
+ end
55
+ end
56
+
57
+ describe CacheManager, "customized" do
58
+ after(:each) do
59
+ @manager.shutdown
60
+ end
61
+
62
+ it "should create a primary cache with values based on default cache" do
63
+ @manager = Ehcache::CacheManager.new
64
+ @manager.cache.max_elements.should == 10000
65
+ end
66
+
67
+ it "should create a cache with cache named steve" do
68
+ @manager = Ehcache::CacheManager.new({"cache" => {"name" => "steve"}})
69
+ @manager.include?("steve").should == true
70
+ end
71
+
72
+ it "should create a custom default and primary cache" do
73
+ @manager = Ehcache::CacheManager.new({
74
+ "default" => {"max_elements_in_memory" => 200000},
75
+ "cache" => {"name" => "cache", "time_to_live_seconds" => 180, "eternal" => true}
76
+ })
77
+ @manager.cache("cache").max_elements.should == 200000
78
+ @manager.cache("cache").ttl.should == 180
79
+ @manager.cache("cache").eternal?.should == true
80
+ end
81
+ end
@@ -0,0 +1,86 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe Cache do
4
+ before(:each) do
5
+ @manager = Ehcache::CacheManager.new
6
+ @cache = @manager.cache
7
+ end
8
+
9
+ after(:each) do
10
+ @manager.shutdown
11
+ end
12
+
13
+ it "should have an alive status on creation" do
14
+ @cache.status.should == Ehcache::Status::ALIVE
15
+ end
16
+
17
+ it "should have a shutdown status when its manager shutsdown" do
18
+ @manager.shutdown
19
+ @cache.status.should == Ehcache::Status::SHUTDOWN
20
+ end
21
+
22
+ it "should return an element value from get when given a valid key" do
23
+ @cache.put("lol", "123456")
24
+ @cache.get("lol").should == "123456"
25
+ end
26
+
27
+ it "should return true when removing an element from the cache given a valid key" do
28
+ @cache.put("lol", "123456")
29
+ @cache.remove("lol").should == true
30
+ end
31
+
32
+ it "should return false when removing an element from the cache given a valid key" do
33
+ @cache.put("lol", "123456")
34
+ @cache.remove("rofl").should == false
35
+ end
36
+
37
+ it "should remove all elements from the cache on a call to remove_all" do
38
+ @cache.put("lol", "123456")
39
+ @cache.put("rofl", "123456")
40
+ @cache.remove_all
41
+ @cache.size.should == 0
42
+ end
43
+
44
+ it "should return true when exist? is called when a valid key is in the cache" do
45
+ @cache.put("lol", "123456")
46
+ @cache.exist?("lol").should == true
47
+ end
48
+
49
+ it "should return false when exist? is called when a valid key is in the cache" do
50
+ @cache.put("lol", "123456")
51
+ @cache.exist?("rofl").should == false
52
+ end
53
+
54
+ it "should raise an EhcacheArgumentException when given an empty key" do
55
+ lambda { @cache.put("", "123456") }.should raise_error(EhcacheError)
56
+ end
57
+
58
+ it "should raise an EhcacheArgumentException when given nil key" do
59
+ lambda { @cache.put(nil, "123456") }.should raise_error(EhcacheError)
60
+ end
61
+
62
+ it "should allow adding an element to the cache with a time to live" do
63
+ @cache.put("lol", "123456", { :ttl => 60 })
64
+ @cache.element("lol").ttl.should == 60
65
+ end
66
+
67
+ it "should return an element from a call to element when given a valid key" do
68
+ @cache.put("lol", "123456")
69
+ @cache.element("lol").class.should == Ehcache::Element
70
+ end
71
+
72
+ it "should return the number of elements in the cache" do
73
+ @cache.size.should == 0
74
+ @cache.put("lol", "123456")
75
+ @cache.size.should == 1
76
+ end
77
+
78
+ it "should return all the keys in the cache" do
79
+ @cache.put("lol", "123456")
80
+ @cache.put("rofl", "123456")
81
+ @cache.keys.size.should == 2
82
+ end
83
+
84
+ it "should return the number of elements in the memory store"
85
+ it "should return the number of elements in the disk store"
86
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format=specdoc
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'spec/story'
4
+ require 'java'
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ehcache]))
7
+ include Ehcache
8
+ include Ehcache::Java
9
+
10
+ Spec::Runner.configure do |config|
11
+ #config.mock_with :mocha
12
+ end
@@ -0,0 +1,15 @@
1
+ package net.sf.ehcache;
2
+
3
+ import java.io.Serializable;
4
+
5
+ public class MarshaledRubyObject implements Serializable {
6
+ private byte[] bytes;
7
+
8
+ public MarshaledRubyObject(byte[] bytes) {
9
+ this.bytes = bytes;
10
+ }
11
+
12
+ public byte[] getBytes() {
13
+ return this.bytes;
14
+ }
15
+ }
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
data/test/ehcache.xml ADDED
@@ -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>
data/test/ehcache.yml ADDED
@@ -0,0 +1,67 @@
1
+ name: testing
2
+ update_check: false
3
+ monitoring: autodetect
4
+ dynamic_config: true
5
+
6
+ disk_store:
7
+ path: java.io.tmpdir
8
+
9
+ transaction_manager:
10
+ class: net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup
11
+ properties: jndiName=java:/TransactionManager
12
+ property_separator: ";"
13
+
14
+ peer_providers:
15
+ - class: net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
16
+ properties: peerDiscovery=automatic,multicastGroupAddress=230.0.0.1,multicastGroupPort=4446,timeToLive=1
17
+ property_separator: ","
18
+
19
+ peer_listeners:
20
+ - class: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory
21
+
22
+ default_cache:
23
+ max_elements_in_memory: 10000
24
+ time_to_live_seconds: 0
25
+ time_to_idle_seconds: 0
26
+ overflow_to_disk: true
27
+ eternal: false
28
+ disk_spool_buffer_size_mb: 30
29
+ disk_persistent: false
30
+ disk_expiry_thread_interval_seconds: 120
31
+ memory_store_eviction_policy: LRU
32
+
33
+ caches:
34
+ # Sample cache named sampleCache1
35
+ - name: sampleCache1
36
+ max_elements_in_memory: 10000
37
+ max_elements_on_disk: 1000
38
+ eternal: false
39
+ time_to_idle_seconds: 360
40
+ time_to_live_seconds: 1000
41
+ overflow_to_disk: true
42
+
43
+ #Sample cache named sampleCache2. Is eternal. Is diskPersistent but does not overflow to disk
44
+ - name: sampleCache2
45
+ max_elements_in_memory: 1000
46
+ eternal: true
47
+ overflow_to_disk: false
48
+ disk_persistent: true
49
+
50
+ - name: sampleCacheWithCacheConfigurations
51
+ max_elements_in_memory: 10
52
+ eternal: false
53
+ time_to_idle_seconds: 100
54
+ time_to_live_seconds: 100
55
+ overflow_to_disk: false
56
+ bootstrap_loader:
57
+ class: net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory
58
+ properties: "bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
59
+ property_separator: ","
60
+ event_listeners:
61
+ - class: net.sf.ehcache.distribution.RMICacheReplicatorFactory
62
+ properties: "replicateAsynchronously=false, replicatePuts=false, replicatePutsViaCopy=false, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=false"
63
+ - class: net.sf.ehcache.distribution.RMICacheReplicatorFactory
64
+ properties: "replicateAsynchronously=false, replicatePuts=false, replicatePutsViaCopy=false, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=false"
65
+ # extensions:
66
+ # - class: com.example.FileWatchingCacheRefresherExtensionFactory
67
+ # properties: "refreshIntervalMillis=18000, loaderTimeout=3000, flushPeriod=whatever, someOtherProperty=someValue"