jruby-ehcache-rails3 0.5.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 +84 -0
- data/bin/ehcache +28 -0
- data/lib/active_support/cache/ehcache_store.rb +76 -0
- metadata +83 -0
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/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,76 @@
|
|
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'
|
8
|
+
|
9
|
+
module ActiveSupport
|
10
|
+
module Cache
|
11
|
+
# A cache store implementation which stores data in Ehcache:
|
12
|
+
# http://www.ehcache.org/
|
13
|
+
class EhcacheStore < Store
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super(*args)
|
17
|
+
@data = Ehcache::CacheManager.new.cache
|
18
|
+
extend Strategy::LocalCache
|
19
|
+
end
|
20
|
+
|
21
|
+
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
|
29
|
+
end
|
30
|
+
|
31
|
+
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
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear(options = nil)
|
42
|
+
@data.remove_all
|
43
|
+
end
|
44
|
+
|
45
|
+
def stats
|
46
|
+
@data.statistics
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
# Read an entry from the cache.
|
51
|
+
def read_entry(key, options) # :nodoc:
|
52
|
+
@data.get(key)
|
53
|
+
rescue Ehcache::EhcacheError => e
|
54
|
+
logger.error("EhcacheError (#{e}): #{e.message}")
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
# Write an entry to the cache.
|
59
|
+
def write_entry(key, entry, options) # :nodoc:
|
60
|
+
@data.set(key, entry, options)
|
61
|
+
true
|
62
|
+
rescue Ehcache::EhcacheError => e
|
63
|
+
logger.error("EhcacheError (#{e}): #{e.message}")
|
64
|
+
false
|
65
|
+
end
|
66
|
+
|
67
|
+
# Delete an entry from the cache.
|
68
|
+
def delete_entry(key, options) # :nodoc:
|
69
|
+
@data.delete(key)
|
70
|
+
rescue Exception => e
|
71
|
+
logger.error("EhcacheError (#{e}): #{e.message}")
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jruby-ehcache-rails3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dylan Stamat
|
13
|
+
- Jason Voegele
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-24 00:00:00 -04:00
|
19
|
+
default_executable: ehcache
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: jruby-ehcache
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 5
|
32
|
+
- 0
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Rails 3 cache store provider using Ehcache
|
37
|
+
email:
|
38
|
+
- dstamat@elctech.com
|
39
|
+
- jvoegele@terracotta.org
|
40
|
+
executables:
|
41
|
+
- ehcache
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.txt
|
46
|
+
files:
|
47
|
+
- lib/active_support/cache/ehcache_store.rb
|
48
|
+
- README.txt
|
49
|
+
- bin/ehcache
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://ehcache.rubyforge.org
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: ehcache
|
78
|
+
rubygems_version: 1.3.7
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Rails 3 cache store provider using Ehcache
|
82
|
+
test_files: []
|
83
|
+
|