jruby-ehcache-rails2 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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:
@@ -0,0 +1,66 @@
1
+ require 'ehcache/rails/ehcache_rails_common'
2
+
3
+ module ActiveSupport
4
+ module Cache
5
+
6
+ # Rails 3 cache store implementation which stores data in Ehcache:
7
+ # http://www.ehcache.org/
8
+ class EhcacheStore < Store
9
+ include Ehcache::Rails
10
+
11
+ def initialize(*args)
12
+ args = args.flatten
13
+ options = args.extract_options!
14
+ super(*options)
15
+ @ehcache = self.create_cache # This comes from the Ehcache::Rails mixin.
16
+ extend Strategy::LocalCache
17
+ end
18
+
19
+ def increment(name, amount = 1, options = nil) # :nodoc:
20
+ @ehcache.compare_and_swap(name) { |current_value|
21
+ current_value + amount
22
+ }
23
+ end
24
+
25
+ def decrement(name, amount = 1, options = nil) # :nodoc:
26
+ @ehcache.compare_and_swap(name) { |current_value|
27
+ current_value - amount
28
+ }
29
+ end
30
+
31
+ def clear(options = nil)
32
+ @ehcache.remove_all
33
+ end
34
+
35
+ def stats
36
+ @ehcache.statistics
37
+ end
38
+
39
+ protected
40
+ # Read an entry from the cache.
41
+ def read_entry(key, options) # :nodoc:
42
+ @ehcache[key]
43
+ rescue Ehcache::EhcacheError => e
44
+ logger.error("EhcacheError (#{e}): #{e.message}")
45
+ false
46
+ end
47
+
48
+ # Write an entry to the cache.
49
+ def write_entry(key, entry, options) # :nodoc:
50
+ @ehcache.put(key, entry, options)
51
+ true
52
+ rescue Ehcache::EhcacheError => e
53
+ logger.error("EhcacheError (#{e}): #{e.message}")
54
+ false
55
+ end
56
+
57
+ # Delete an entry from the cache.
58
+ def delete_entry(key, options) # :nodoc:
59
+ @ehcache.remove(key)
60
+ rescue Exception => e
61
+ logger.error("EhcacheError (#{e}): #{e.message}")
62
+ false
63
+ end
64
+ end
65
+ end
66
+ end
@@ -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-rails2
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 2 cache store provider using Ehcache
@@ -44,9 +43,9 @@ extensions: []
44
43
  extra_rdoc_files:
45
44
  - README.txt
46
45
  files:
47
- - lib/ehcache_store.rb
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 2 cache store provider using Ehcache
data/lib/ehcache_store.rb DELETED
@@ -1,59 +0,0 @@
1
- require 'activesupport'
2
- require 'ehcache'
3
-
4
- module ActiveSupport
5
- module Cache
6
- class EhcacheStore < Store
7
- def initialize(options = {})
8
- manager = Ehcache::CacheManager.new(options)
9
- @data = manager.cache
10
- end
11
-
12
- def read(key, options = nil)
13
- super
14
- @data.get(key)
15
- rescue Ehcache::EhcacheError => e
16
- logger.error("EhcacheError (#{e}): #{e.message}")
17
- false
18
- end
19
-
20
- def write(key, value, options = nil)
21
- super
22
- @data.set(key, value, options)
23
- true
24
- rescue Ehcache::EhcacheError => e
25
- logger.error("EhcacheError (#{e}): #{e.message}")
26
- false
27
- end
28
-
29
- def delete(key, options = nil)
30
- super
31
- @data.delete(key)
32
- rescue Exception => e
33
- logger.error("EhcacheError (#{e}): #{e.message}")
34
- false
35
- end
36
-
37
- def keys
38
- @data.keys
39
- end
40
-
41
- def exist?(key, options = nil)
42
- @data.exist?(key)
43
- end
44
-
45
- def delete_matched(matcher, options = nil)
46
- super
47
- raise "Not supported by Ehcache"
48
- end
49
-
50
- def clear
51
- @data.clear
52
- true
53
- rescue Exception => e
54
- logger.error("EhcacheError (#{e}): #{e.message}")
55
- false
56
- end
57
- end
58
- end
59
- end