mem_cache_fragment_store 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/History.txt +4 -0
- data/LICENSE.txt +26 -0
- data/Manifest.txt +6 -0
- data/README.txt +31 -0
- data/Rakefile +19 -0
- data/lib/mem_cache_fragment_store.rb +59 -0
- metadata +69 -0
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright 2006, Bob Cottrell, The Robot Co-op. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
3. Neither the names of the authors nor the names of their contributors
|
13
|
+
may be used to endorse or promote products derived from this software
|
14
|
+
without specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
17
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
|
20
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
22
|
+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
23
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
24
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
25
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
26
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= mem_cache_fragment_store
|
2
|
+
|
3
|
+
Rubyforge Project:
|
4
|
+
|
5
|
+
http://rubyforge.org/projects/rctools
|
6
|
+
|
7
|
+
Documentation:
|
8
|
+
|
9
|
+
http://dev.robotcoop.com/Libraries/mem_cache_fragment_store
|
10
|
+
|
11
|
+
== About
|
12
|
+
|
13
|
+
mem_cache_fragment_store is an improved Rails fragment cache that rescues
|
14
|
+
errors and reuses memcache servers allowing you to instantiate the store only
|
15
|
+
once.
|
16
|
+
|
17
|
+
== Installing mem_cache_fragment_store
|
18
|
+
|
19
|
+
Just install the gem:
|
20
|
+
|
21
|
+
$ sudo gem install mem_cache_fragment_store
|
22
|
+
|
23
|
+
== Using mem_cache_fragment_store
|
24
|
+
|
25
|
+
Edit your config/environment.rb:
|
26
|
+
|
27
|
+
CACHE = MemCache.new %w[10.0.0.2:11211 10.0.0.1:11211],
|
28
|
+
:namespace => 'your_app'
|
29
|
+
|
30
|
+
ActionController::Base.fragment_cache_store = :mem_cache_fragment_store, CACHE
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# vim: syntax=Ruby
|
2
|
+
|
3
|
+
require 'hoe'
|
4
|
+
|
5
|
+
DEV_DOC_PATH = 'Libraries/mem_cache_fragment_store'
|
6
|
+
|
7
|
+
SPEC = Hoe.new 'mem_cache_fragment_store', '1.0.0' do |p|
|
8
|
+
p.summary = 'A better Rails fragment store than MemCacheStore'
|
9
|
+
p.description = 'MemCacheFragementStore correctly handles errors and reuses the CACHE object rather than creating a new client.'
|
10
|
+
p.author = 'Bob Cottrell'
|
11
|
+
p.email = 'eric@robotcoop.com'
|
12
|
+
p.url = "http://dev.robotcoop.com/#{DEV_DOC_PATH}"
|
13
|
+
p.rubyforge_name = 'rctools'
|
14
|
+
|
15
|
+
p.extra_deps << ['memcache-client', '>= 1.1.0']
|
16
|
+
end
|
17
|
+
|
18
|
+
require '../tasks'
|
19
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'action_controller/caching'
|
2
|
+
require 'memcache'
|
3
|
+
|
4
|
+
##
|
5
|
+
# MemCache-base fragment cache storage class.
|
6
|
+
#
|
7
|
+
# This builds upon the top-level MemCache class provided by the library file
|
8
|
+
# memcache.rb. Fragment cache data is marshalled and stored in a memcached
|
9
|
+
# cache.
|
10
|
+
|
11
|
+
class ActionController::Caching::Fragments::UnthreadedMemCacheFragmentStore
|
12
|
+
|
13
|
+
attr_accessor :data
|
14
|
+
attr_accessor :ttl
|
15
|
+
|
16
|
+
def initialize(cache, ttl = 0)
|
17
|
+
@data = cache
|
18
|
+
@ttl = ttl
|
19
|
+
end
|
20
|
+
|
21
|
+
def read(name, options = nil)
|
22
|
+
@data.get "fragment:#{name}"
|
23
|
+
rescue MemCache::MemCacheError => err
|
24
|
+
Base.logger.error "MemCacheFragmentStore Error: #{err.message}" if
|
25
|
+
Base.logger
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def write(name, value, options = nil)
|
30
|
+
@data.set "fragment:#{name}", value, @ttl
|
31
|
+
rescue MemCache::MemCacheError => err
|
32
|
+
return unless Base.logger
|
33
|
+
Base.logger.error "MemCacheFragmentStore Error: #{err.message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(name, options = nil)
|
37
|
+
@data.delete "fragment:#{name}"
|
38
|
+
rescue MemCache::MemCacheError => err
|
39
|
+
return unless Base.logger
|
40
|
+
Base.logger.error "MemCacheFragmentStore Error: #{err.message}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_matched(matcher, options = nil)
|
44
|
+
return unless Base.logger
|
45
|
+
Base.logger.error "MemCacheFragmentStore#delete_matched is not supported"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class ActionController::Caching::Fragments::MemCacheFragmentStore <
|
51
|
+
ActionController::Caching::Fragments::UnthreadedMemCacheFragmentStore
|
52
|
+
def initialize(cache, ttl = 0)
|
53
|
+
super
|
54
|
+
return unless ActionController::Base.allow_concurrency
|
55
|
+
@mutex = Mutex.new
|
56
|
+
MemCacheFragmentStore.send :include, ThreadSafety
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.99
|
3
|
+
specification_version: 1
|
4
|
+
name: mem_cache_fragment_store
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2006-09-29 00:00:00 -07:00
|
8
|
+
summary: A better Rails fragment store than MemCacheStore
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- test
|
12
|
+
email: eric@robotcoop.com
|
13
|
+
homepage: http://dev.robotcoop.com/Libraries/mem_cache_fragment_store
|
14
|
+
rubyforge_project: rctools
|
15
|
+
description: MemCacheFragementStore correctly handles errors and reuses the CACHE object rather than creating a new client.
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
post_install_message:
|
30
|
+
authors:
|
31
|
+
- Bob Cottrell
|
32
|
+
files:
|
33
|
+
- History.txt
|
34
|
+
- LICENSE.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- README.txt
|
37
|
+
- Rakefile
|
38
|
+
- lib/mem_cache_fragment_store.rb
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: hoe
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.0.0
|
60
|
+
version:
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: memcache-client
|
63
|
+
version_requirement:
|
64
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.0
|
69
|
+
version:
|