jruby-ehcache-rails3 0.5.0 → 1.0.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/README.txt CHANGED
@@ -1,14 +1,14 @@
1
- = Ehcache for JRuby
1
+ = jruby-ehcache - Ehcache for JRuby
2
2
 
3
3
  http://github.com/dylanz/ehcache
4
4
 
5
5
  == DESCRIPTION:
6
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.
7
+ jruby-ehcache is a JRuby interface to Java's (JSR-107 compliant) Ehcache.
8
+ It provides 100% full coverage of the native Ehcache API and also provides
9
+ some Rubyesque enhancements to make it idiomatic to Ruby developers.
10
+ Configuration is done with the traditional ehcache.xml file that Java
11
+ developers use.
12
12
 
13
13
  Some biased and non-biased Ehcache VS Memcache articles:
14
14
  http://gregluck.com/blog/archives/2007/05/comparing_memca.html
@@ -30,33 +30,35 @@ http://dylanz.lighthouseapp.com/projects/14518-ehcache-jruby/overview
30
30
 
31
31
 
32
32
  == BASIC USAGE:
33
-
33
+ require 'ehcache'
34
34
  manager = CacheManager.new
35
35
  cache = manager.cache
36
36
  cache.put("key", "value", {:ttl => 120})
37
- cache.get("key")
37
+ cache.get("key") # => returns the Ehcache Element object
38
+ cache["key"] # => returns "value", the value of the Element
38
39
  manager.shutdown
39
40
 
40
41
 
41
42
  == RAILS:
42
43
 
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.:
44
+ Rails 2 and Rails 3 integration are provided by the separate
45
+ jruby-ehcache-rails2 and jruby-ehcache-rails3 gems. To install, choose the
46
+ correct version for your Rails application and use JRuby's gem command to
47
+ install, e.g.:
46
48
 
47
- $ jgem install ehcache-rails3
49
+ $ jgem install jruby-ehcache-rails3
48
50
  OR
49
- $ jruby -S gem install ehcache-rails3
51
+ $ jruby -S gem install jruby-ehcache-rails3
50
52
 
51
53
 
52
54
  == REQUIREMENTS:
53
55
 
54
- Tested with JRuby 1.5.0.
56
+ Tested with JRuby 1.5.3.
55
57
 
56
58
 
57
59
  == INSTALL:
58
60
 
59
- $ sudo jruby -S gem install ehcache
61
+ $ sudo jruby -S gem install jruby-ehcache
60
62
 
61
63
 
62
64
  == LICENSE:
@@ -1,55 +1,45 @@
1
- begin
2
- require 'ehcache'
3
- rescue LoadError => e
4
- $stderr.puts "You don't have ehcache installed in your application. Please add it to your Gemfile and run bundle install"
5
- raise e
6
- end
7
- #require 'digest/md5'
1
+ require 'ehcache/rails/ehcache_rails_common'
8
2
 
9
3
  module ActiveSupport
10
4
  module Cache
11
- # A cache store implementation which stores data in Ehcache:
5
+
6
+ # Rails 3 cache store implementation which stores data in Ehcache:
12
7
  # http://www.ehcache.org/
13
8
  class EhcacheStore < Store
9
+ include Ehcache::Rails
14
10
 
15
11
  def initialize(*args)
16
- super(*args)
17
- @data = Ehcache::CacheManager.new.cache
12
+ args = args.flatten
13
+ options = args.extract_options!
14
+ super(*options)
15
+ @ehcache = self.create_cache # This comes from the Ehcache::Rails mixin.
18
16
  extend Strategy::LocalCache
19
17
  end
20
18
 
21
19
  def increment(name, amount = 1, options = nil) # :nodoc:
22
- if num = @data.get(name)
23
- num = num.to_i + amount
24
- @data.put(name, num, options)
25
- num
26
- else
27
- nil
28
- end
20
+ @ehcache.compare_and_swap(name) { |current_value|
21
+ current_value + amount
22
+ }
29
23
  end
30
24
 
31
25
  def decrement(name, amount = 1, options = nil) # :nodoc:
32
- if num = @data.get(name)
33
- num = num.to_i - amount
34
- @data.put(name, num, options)
35
- num
36
- else
37
- nil
38
- end
26
+ @ehcache.compare_and_swap(name) { |current_value|
27
+ current_value - amount
28
+ }
39
29
  end
40
30
 
41
31
  def clear(options = nil)
42
- @data.remove_all
32
+ @ehcache.remove_all
43
33
  end
44
34
 
45
35
  def stats
46
- @data.statistics
36
+ @ehcache.statistics
47
37
  end
48
38
 
49
39
  protected
50
40
  # Read an entry from the cache.
51
41
  def read_entry(key, options) # :nodoc:
52
- @data.get(key)
42
+ @ehcache[key]
53
43
  rescue Ehcache::EhcacheError => e
54
44
  logger.error("EhcacheError (#{e}): #{e.message}")
55
45
  false
@@ -57,7 +47,7 @@ module ActiveSupport
57
47
 
58
48
  # Write an entry to the cache.
59
49
  def write_entry(key, entry, options) # :nodoc:
60
- @data.set(key, entry, options)
50
+ @ehcache.put(key, entry, options)
61
51
  true
62
52
  rescue Ehcache::EhcacheError => e
63
53
  logger.error("EhcacheError (#{e}): #{e.message}")
@@ -66,7 +56,7 @@ module ActiveSupport
66
56
 
67
57
  # Delete an entry from the cache.
68
58
  def delete_entry(key, options) # :nodoc:
69
- @data.delete(key)
59
+ @ehcache.remove(key)
70
60
  rescue Exception => e
71
61
  logger.error("EhcacheError (#{e}): #{e.message}")
72
62
  false
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'ehcache'
3
+ rescue LoadError => e
4
+ $stderr.puts "You don't have ehcache installed in your application."
5
+ $stderr.puts "Please add it to your Gemfile and run bundle install"
6
+ raise e
7
+ end
8
+
9
+ module Ehcache
10
+ # Mixin module providing facilities for the Rails 2 and Rails 3 Cache::Store
11
+ # implementations.
12
+ module Rails
13
+
14
+ RAILS_CONFIG_DIR =
15
+ if defined?(::Rails)
16
+ File.join(::Rails.root.to_s, 'config')
17
+ elsif defined?(RAILS_ROOT)
18
+ File.join(RAILS_ROOT, 'config')
19
+ end
20
+
21
+ DEFAULT_RAILS_CACHE_NAME = 'rails_cache'
22
+
23
+ def create_cache_manager(*args)
24
+ config = Ehcache::Config::Configuration.find(RAILS_CONFIG_DIR)
25
+ @cache_manager = Ehcache::CacheManager.create(config)
26
+ end
27
+
28
+ def create_cache(name = DEFAULT_RAILS_CACHE_NAME)
29
+ create_cache_manager if @cache_manager.nil?
30
+ @cache = @cache_manager.cache(name)
31
+ end
32
+
33
+ at_exit do
34
+ @cache_manager.shutdown if @cache_manager
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -3,10 +3,10 @@ name: jruby-ehcache-rails3
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 5
8
8
  - 0
9
- version: 0.5.0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dylan Stamat
@@ -15,22 +15,21 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-24 00:00:00 -04:00
18
+ date: 2010-11-15 00:00:00 -05:00
19
19
  default_executable: ehcache
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: jruby-ehcache
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
28
  segments:
29
+ - 1
30
30
  - 0
31
- - 5
32
31
  - 0
33
- version: 0.5.0
32
+ version: 1.0.0
34
33
  type: :runtime
35
34
  version_requirements: *id001
36
35
  description: Rails 3 cache store provider using Ehcache
@@ -45,8 +44,8 @@ extra_rdoc_files:
45
44
  - README.txt
46
45
  files:
47
46
  - lib/active_support/cache/ehcache_store.rb
47
+ - lib/ehcache/rails/ehcache_rails_common.rb
48
48
  - README.txt
49
- - bin/ehcache
50
49
  has_rdoc: true
51
50
  homepage: http://ehcache.rubyforge.org
52
51
  licenses: []
@@ -57,7 +56,6 @@ rdoc_options:
57
56
  require_paths:
58
57
  - lib
59
58
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
59
  requirements:
62
60
  - - ">="
63
61
  - !ruby/object:Gem::Version
@@ -65,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
63
  - 0
66
64
  version: "0"
67
65
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
66
  requirements:
70
67
  - - ">="
71
68
  - !ruby/object:Gem::Version
@@ -75,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
72
  requirements: []
76
73
 
77
74
  rubyforge_project: ehcache
78
- rubygems_version: 1.3.7
75
+ rubygems_version: 1.3.6
79
76
  signing_key:
80
77
  specification_version: 3
81
78
  summary: Rails 3 cache store provider using Ehcache