cachetastic 2.1.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +57 -43
- data/doc/classes/Cachetastic/Adapters.html +180 -0
- data/doc/classes/Cachetastic/Adapters/Base.html +206 -123
- data/doc/classes/Cachetastic/Adapters/File.html +17 -130
- data/doc/classes/Cachetastic/Adapters/LocalMemory.html +7 -228
- data/doc/classes/Cachetastic/Adapters/Memcached.html +193 -0
- data/doc/classes/Cachetastic/Cache.html +425 -0
- data/doc/classes/Cachetastic/Cacheable.html +26 -30
- data/doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html +66 -62
- data/doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html +30 -30
- data/doc/classes/Cachetastic/Logger.html +31 -33
- data/doc/created.rid +1 -1
- data/doc/files/{lib/cachetastic/adapters/html_file_rb.html → LICENSE.html} +29 -34
- data/doc/files/README.html +91 -57
- data/doc/files/lib/cachetastic/adapters/base_rb.html +1 -39
- data/doc/files/lib/cachetastic/adapters/file_rb.html +1 -21
- data/doc/files/lib/cachetastic/adapters/local_memory_rb.html +1 -9
- data/doc/files/lib/cachetastic/{ruby_extensions/kernel_rb.html → adapters/memcached_rb.html} +4 -4
- data/doc/files/lib/cachetastic/{ruby_extensions/string_rb.html → cache_rb.html} +5 -5
- data/doc/files/lib/cachetastic/cacheable_rb.html +1 -1
- data/doc/files/lib/cachetastic/{caches/base_rb.html → extensions/string_rb.html} +5 -5
- data/doc/files/lib/cachetastic/logger_rb.html +1 -7
- data/doc/files/lib/cachetastic/{adapters/store_object_rb.html → store_object_rb.html} +3 -3
- data/doc/files/lib/cachetastic_rb.html +4 -95
- data/doc/fr_class_index.html +3 -15
- data/doc/fr_file_index.html +5 -16
- data/doc/fr_method_index.html +26 -78
- data/lib/cachetastic.rb +16 -70
- data/lib/cachetastic/adapters/base.rb +178 -76
- data/lib/cachetastic/adapters/file.rb +63 -46
- data/lib/cachetastic/adapters/local_memory.rb +36 -67
- data/lib/cachetastic/adapters/memcached.rb +114 -0
- data/lib/cachetastic/cache.rb +165 -0
- data/lib/cachetastic/cacheable.rb +19 -15
- data/lib/cachetastic/extensions/string.rb +8 -0
- data/lib/cachetastic/logger.rb +41 -41
- data/lib/cachetastic/store_object.rb +22 -0
- metadata +43 -64
- data/bin/cachetastic_drb_server +0 -115
- data/doc/classes/ActiveRecord/Base.html +0 -194
- data/doc/classes/CGI/Session/CachetasticStore.html +0 -124
- data/doc/classes/Cachetastic/Adapters/Drb.html +0 -332
- data/doc/classes/Cachetastic/Adapters/FileBase.html +0 -309
- data/doc/classes/Cachetastic/Adapters/HtmlFile.html +0 -224
- data/doc/classes/Cachetastic/Adapters/Memcache.html +0 -498
- data/doc/classes/Cachetastic/Caches/Base.html +0 -643
- data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html +0 -179
- data/doc/classes/Cachetastic/Caches/MackSessionCache.html +0 -119
- data/doc/classes/Cachetastic/Caches/PageCache.html +0 -121
- data/doc/classes/Cachetastic/Caches/RailsSessionCache.html +0 -154
- data/doc/classes/Cachetastic/Connection.html +0 -212
- data/doc/classes/Cachetastic/Errors/UnsupportedAdapter.html +0 -146
- data/doc/classes/Object.html +0 -222
- data/doc/classes/String.html +0 -172
- data/doc/files/lib/cachetastic/adapters/drb_rb.html +0 -115
- data/doc/files/lib/cachetastic/adapters/file_base_rb.html +0 -109
- data/doc/files/lib/cachetastic/adapters/memcache_rb.html +0 -127
- data/doc/files/lib/cachetastic/caches/mack_session_cache_rb.html +0 -107
- data/doc/files/lib/cachetastic/caches/page_cache_rb.html +0 -109
- data/doc/files/lib/cachetastic/caches/rails_session_cache_rb.html +0 -107
- data/doc/files/lib/cachetastic/connection_rb.html +0 -107
- data/doc/files/lib/cachetastic/errors/unsupported_adapter_rb.html +0 -101
- data/doc/files/lib/cachetastic/rails_extensions/active_record_base_rb.html +0 -101
- data/doc/files/lib/cachetastic/rails_extensions/cgi_session_store_rb.html +0 -109
- data/doc/files/lib/cachetastic/ruby_extensions/object_rb.html +0 -101
- data/lib/cachetastic/adapters/drb.rb +0 -51
- data/lib/cachetastic/adapters/file_base.rb +0 -86
- data/lib/cachetastic/adapters/html_file.rb +0 -68
- data/lib/cachetastic/adapters/memcache.rb +0 -114
- data/lib/cachetastic/adapters/store_object.rb +0 -28
- data/lib/cachetastic/caches/base.rb +0 -238
- data/lib/cachetastic/caches/mack_session_cache.rb +0 -3
- data/lib/cachetastic/caches/page_cache.rb +0 -6
- data/lib/cachetastic/caches/rails_session_cache.rb +0 -12
- data/lib/cachetastic/connection.rb +0 -24
- data/lib/cachetastic/errors/unsupported_adapter.rb +0 -7
- data/lib/cachetastic/rails_extensions/active_record_base.rb +0 -24
- data/lib/cachetastic/rails_extensions/cgi_session_store.rb +0 -59
- data/lib/cachetastic/ruby_extensions/kernel.rb +0 -25
- data/lib/cachetastic/ruby_extensions/object.rb +0 -22
- data/lib/cachetastic/ruby_extensions/string.rb +0 -15
- data/test/active_record_test.rb +0 -89
- data/test/cacheable_test.rb +0 -88
- data/test/cachetastic_unit_test.rb +0 -74
- data/test/config.rb +0 -30
- data/test/drb_adapter_test.rb +0 -14
- data/test/file_adapter_test.rb +0 -49
- data/test/memcache_adapter_test.rb +0 -18
- data/test/test_helper.rb +0 -75
@@ -1,4 +1,4 @@
|
|
1
|
-
module Cachetastic
|
1
|
+
module Cachetastic # :nodoc:
|
2
2
|
# Include this module into an Object to achieve simplistic Object level caching.
|
3
3
|
#
|
4
4
|
# Example:
|
@@ -21,31 +21,37 @@ module Cachetastic
|
|
21
21
|
module Cacheable
|
22
22
|
|
23
23
|
module ClassAndInstanceMethods
|
24
|
-
# Returns the Cachetastic::
|
24
|
+
# Returns the Cachetastic::Cache object associated with the object.
|
25
25
|
# If a cache hasn't been defined the one will be created on the fly.
|
26
26
|
# The cache for the object is expected to be defined as:
|
27
27
|
# Cachetastic::Cacheable::{CLASS_NAME_HERE}Cache
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# Examples:
|
30
30
|
# class Person
|
31
31
|
# include Cachetastic::Cacheable
|
32
|
-
# attr_accessor :name
|
33
|
-
# def cachetastic_key
|
34
|
-
# self.name
|
35
|
-
# end
|
36
32
|
# end
|
37
33
|
#
|
38
34
|
# Person.cache_class # => Cachetastic::Cacheable::PersonCache
|
35
|
+
#
|
36
|
+
# class Admin::Person
|
37
|
+
# include Cachetastic::Cacheable
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# Admin::Person.cache_class # => Cachetastic::Cacheable::Admin_PersonCache
|
39
41
|
def cache_class
|
40
42
|
n = self.class.name
|
41
43
|
n = self.name if n == "Class"
|
42
|
-
n.gsub
|
43
|
-
c_name = "Cachetastic::Cacheable::#{n}Cache"
|
44
|
+
c_name = "Cachetastic::Cacheable::#{n.gsub('::', '_')}Cache"
|
44
45
|
begin
|
45
46
|
return c_name.constantize
|
46
47
|
rescue NameError => e
|
47
48
|
eval %{
|
48
|
-
class #{c_name} < Cachetastic::
|
49
|
+
class #{c_name} < Cachetastic::Cache
|
50
|
+
|
51
|
+
def self.cache_klass
|
52
|
+
#{n}
|
53
|
+
end
|
54
|
+
|
49
55
|
end
|
50
56
|
}
|
51
57
|
return c_name.constantize
|
@@ -62,10 +68,7 @@ module Cachetastic
|
|
62
68
|
# Example:
|
63
69
|
# class Person
|
64
70
|
# include Cachetastic::Cacheable
|
65
|
-
#
|
66
|
-
# def cachetastic_key
|
67
|
-
# self.name
|
68
|
-
# end
|
71
|
+
#
|
69
72
|
# def always_the_same(x,y)
|
70
73
|
# cacher("always_the_same") do
|
71
74
|
# x + y
|
@@ -83,7 +86,7 @@ module Cachetastic
|
|
83
86
|
# Person.cacher("say_hi") {"Hi There"} # => "Hi There"
|
84
87
|
# Person.get_from_cache("say_hi") # => "Hi There"
|
85
88
|
# Cachetastic::Cacheable::PersonCache.get("say_hi") # => "Hi There"
|
86
|
-
def cacher(key, expiry =
|
89
|
+
def cacher(key, expiry = nil)
|
87
90
|
cache_class.get(key) do
|
88
91
|
if block_given?
|
89
92
|
res = yield
|
@@ -114,6 +117,7 @@ module Cachetastic
|
|
114
117
|
def expire_all
|
115
118
|
cache_class.expire_all
|
116
119
|
end
|
120
|
+
|
117
121
|
end
|
118
122
|
|
119
123
|
# --------------------------
|
data/lib/cachetastic/logger.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
|
2
|
-
class
|
1
|
+
module Cachetastic # :nodoc:
|
2
|
+
# This class handles logging for the caches and their adapters.
|
3
|
+
# This class exists simply to supply the ability to write to
|
4
|
+
# multiple loggers simultaneously from a single call. It also
|
5
|
+
# creates a standardized message to write to those loggers.
|
6
|
+
#
|
7
|
+
# It is important that any logger type of class you decide to use
|
8
|
+
# reponds to the following methods:
|
9
|
+
# fatal(message)
|
10
|
+
# error(message)
|
11
|
+
# warn(message)
|
12
|
+
# info(message)
|
13
|
+
# debug(message)
|
14
|
+
class Logger
|
3
15
|
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :loggers
|
16
|
+
# An <tt>Array</tt> of 'real' loggers to write to.
|
17
|
+
attr_accessor :loggers
|
7
18
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# opts["level"] = (opts["level"] ||= "info").to_sym
|
14
|
-
# end
|
15
|
-
end
|
19
|
+
# The <tt>initialize</tt> method takes an <tt>Array</tt>
|
20
|
+
# of your favorite logger style classes to write to.
|
21
|
+
def initialize(*loggers)
|
22
|
+
@loggers = [loggers].flatten
|
23
|
+
end
|
16
24
|
|
17
|
-
|
25
|
+
LOG_LEVELS = [:fatal, :error, :warn, :info, :debug] # :nodoc:
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
LOG_LEVELS.each do |level|
|
28
|
+
define_method(level) do |*args|
|
29
|
+
lm = "[CACHE] [#{level.to_s.upcase}]\t#{Time.now.strftime("%m/%d/%y %H:%M:%S")}"
|
30
|
+
exs = []
|
31
|
+
args.each do |arg|
|
32
|
+
if arg.is_a?(Exception)
|
33
|
+
exs << arg
|
34
|
+
continue
|
35
|
+
end
|
36
|
+
lm << "\t" << arg.to_s
|
37
|
+
end
|
38
|
+
exs.each do |ex|
|
39
|
+
lm << "\n#{ex.message}\n" << ex.backtrace.join("\n")
|
40
|
+
end
|
41
|
+
# puts "lm: #{lm}"
|
42
|
+
self.loggers.each do |log|
|
43
|
+
log.send(level, lm)
|
27
44
|
end
|
28
|
-
lm << "\t" << arg.to_s
|
29
|
-
end
|
30
|
-
exs.each do |ex|
|
31
|
-
lm << "\n#{ex.message}\n" << ex.backtrace.join("\n")
|
32
|
-
end
|
33
|
-
self.loggers.each do |log|
|
34
|
-
log.send(level, lm)
|
35
45
|
end
|
36
|
-
# self.options.each_pair do |n, opts|
|
37
|
-
# if LOG_LEVELS.index(opts["level"]) >= LOG_LEVELS.index(level)
|
38
|
-
# case opts["type"]
|
39
|
-
# when "file"
|
40
|
-
# File.open(opts["file"], "a") {|f| f.puts(lm)}
|
41
|
-
# when "console"
|
42
|
-
# puts lm
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
# end
|
46
46
|
end
|
47
|
-
end
|
48
47
|
|
49
|
-
end
|
48
|
+
end # Logger
|
49
|
+
end # Cachetastic
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Cachetastic # :nodoc:
|
2
|
+
class Cache
|
3
|
+
|
4
|
+
class StoreObject # :nodoc:
|
5
|
+
attr_accessor :expires_at
|
6
|
+
attr_accessor :key
|
7
|
+
attr_accessor :value
|
8
|
+
|
9
|
+
def initialize(key, value, expires_at)
|
10
|
+
self.key = key
|
11
|
+
self.value = value
|
12
|
+
self.expires_at = expires_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def expired?
|
16
|
+
return Time.now > self.expires_at
|
17
|
+
end
|
18
|
+
|
19
|
+
end # StoreObject
|
20
|
+
|
21
|
+
end # Cache
|
22
|
+
end # Cachetastic
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachetastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Mark Bates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-11 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,85 +20,72 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.3.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: memcache-client
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.3.2
|
24
44
|
version:
|
25
45
|
description: A very simple, yet very powerful caching framework for Ruby.
|
26
46
|
email: mark@mackframework.com
|
27
|
-
executables:
|
28
|
-
|
47
|
+
executables: []
|
48
|
+
|
29
49
|
extensions: []
|
30
50
|
|
31
51
|
extra_rdoc_files:
|
32
52
|
- README
|
53
|
+
- LICENSE
|
33
54
|
files:
|
34
55
|
- lib/cachetastic/adapters/base.rb
|
35
|
-
- lib/cachetastic/adapters/drb.rb
|
36
56
|
- lib/cachetastic/adapters/file.rb
|
37
|
-
- lib/cachetastic/adapters/file_base.rb
|
38
|
-
- lib/cachetastic/adapters/html_file.rb
|
39
57
|
- lib/cachetastic/adapters/local_memory.rb
|
40
|
-
- lib/cachetastic/adapters/
|
41
|
-
- lib/cachetastic/
|
58
|
+
- lib/cachetastic/adapters/memcached.rb
|
59
|
+
- lib/cachetastic/cache.rb
|
42
60
|
- lib/cachetastic/cacheable.rb
|
43
|
-
- lib/cachetastic/
|
44
|
-
- lib/cachetastic/caches/mack_session_cache.rb
|
45
|
-
- lib/cachetastic/caches/page_cache.rb
|
46
|
-
- lib/cachetastic/caches/rails_session_cache.rb
|
47
|
-
- lib/cachetastic/connection.rb
|
48
|
-
- lib/cachetastic/errors/unsupported_adapter.rb
|
61
|
+
- lib/cachetastic/extensions/string.rb
|
49
62
|
- lib/cachetastic/logger.rb
|
50
|
-
- lib/cachetastic/
|
51
|
-
- lib/cachetastic/rails_extensions/cgi_session_store.rb
|
52
|
-
- lib/cachetastic/ruby_extensions/kernel.rb
|
53
|
-
- lib/cachetastic/ruby_extensions/object.rb
|
54
|
-
- lib/cachetastic/ruby_extensions/string.rb
|
63
|
+
- lib/cachetastic/store_object.rb
|
55
64
|
- lib/cachetastic.rb
|
56
65
|
- README
|
57
|
-
-
|
66
|
+
- LICENSE
|
58
67
|
- doc/classes/Cachetastic/Adapters/Base.html
|
59
|
-
- doc/classes/Cachetastic/Adapters/Drb.html
|
60
68
|
- doc/classes/Cachetastic/Adapters/File.html
|
61
|
-
- doc/classes/Cachetastic/Adapters/FileBase.html
|
62
|
-
- doc/classes/Cachetastic/Adapters/HtmlFile.html
|
63
69
|
- doc/classes/Cachetastic/Adapters/LocalMemory.html
|
64
|
-
- doc/classes/Cachetastic/Adapters/
|
70
|
+
- doc/classes/Cachetastic/Adapters/Memcached.html
|
71
|
+
- doc/classes/Cachetastic/Adapters.html
|
72
|
+
- doc/classes/Cachetastic/Cache.html
|
65
73
|
- doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html
|
66
74
|
- doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html
|
67
75
|
- doc/classes/Cachetastic/Cacheable.html
|
68
|
-
- doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html
|
69
|
-
- doc/classes/Cachetastic/Caches/Base.html
|
70
|
-
- doc/classes/Cachetastic/Caches/MackSessionCache.html
|
71
|
-
- doc/classes/Cachetastic/Caches/PageCache.html
|
72
|
-
- doc/classes/Cachetastic/Caches/RailsSessionCache.html
|
73
|
-
- doc/classes/Cachetastic/Connection.html
|
74
|
-
- doc/classes/Cachetastic/Errors/UnsupportedAdapter.html
|
75
76
|
- doc/classes/Cachetastic/Logger.html
|
76
|
-
- doc/classes/CGI/Session/CachetasticStore.html
|
77
|
-
- doc/classes/Object.html
|
78
|
-
- doc/classes/String.html
|
79
77
|
- doc/created.rid
|
80
78
|
- doc/files/lib/cachetastic/adapters/base_rb.html
|
81
|
-
- doc/files/lib/cachetastic/adapters/drb_rb.html
|
82
|
-
- doc/files/lib/cachetastic/adapters/file_base_rb.html
|
83
79
|
- doc/files/lib/cachetastic/adapters/file_rb.html
|
84
|
-
- doc/files/lib/cachetastic/adapters/html_file_rb.html
|
85
80
|
- doc/files/lib/cachetastic/adapters/local_memory_rb.html
|
86
|
-
- doc/files/lib/cachetastic/adapters/
|
87
|
-
- doc/files/lib/cachetastic/
|
81
|
+
- doc/files/lib/cachetastic/adapters/memcached_rb.html
|
82
|
+
- doc/files/lib/cachetastic/cache_rb.html
|
88
83
|
- doc/files/lib/cachetastic/cacheable_rb.html
|
89
|
-
- doc/files/lib/cachetastic/
|
90
|
-
- doc/files/lib/cachetastic/caches/mack_session_cache_rb.html
|
91
|
-
- doc/files/lib/cachetastic/caches/page_cache_rb.html
|
92
|
-
- doc/files/lib/cachetastic/caches/rails_session_cache_rb.html
|
93
|
-
- doc/files/lib/cachetastic/connection_rb.html
|
94
|
-
- doc/files/lib/cachetastic/errors/unsupported_adapter_rb.html
|
84
|
+
- doc/files/lib/cachetastic/extensions/string_rb.html
|
95
85
|
- doc/files/lib/cachetastic/logger_rb.html
|
96
|
-
- doc/files/lib/cachetastic/
|
97
|
-
- doc/files/lib/cachetastic/rails_extensions/cgi_session_store_rb.html
|
98
|
-
- doc/files/lib/cachetastic/ruby_extensions/kernel_rb.html
|
99
|
-
- doc/files/lib/cachetastic/ruby_extensions/object_rb.html
|
100
|
-
- doc/files/lib/cachetastic/ruby_extensions/string_rb.html
|
86
|
+
- doc/files/lib/cachetastic/store_object_rb.html
|
101
87
|
- doc/files/lib/cachetastic_rb.html
|
88
|
+
- doc/files/LICENSE.html
|
102
89
|
- doc/files/README.html
|
103
90
|
- doc/fr_class_index.html
|
104
91
|
- doc/fr_file_index.html
|
@@ -106,13 +93,12 @@ files:
|
|
106
93
|
- doc/index.html
|
107
94
|
- doc/rdoc-style.css
|
108
95
|
has_rdoc: true
|
109
|
-
homepage: http://www.
|
96
|
+
homepage: http://www.metabates.com
|
110
97
|
post_install_message:
|
111
98
|
rdoc_options: []
|
112
99
|
|
113
100
|
require_paths:
|
114
101
|
- lib
|
115
|
-
- lib
|
116
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
103
|
requirements:
|
118
104
|
- - ">="
|
@@ -132,12 +118,5 @@ rubygems_version: 1.3.1
|
|
132
118
|
signing_key:
|
133
119
|
specification_version: 2
|
134
120
|
summary: A very simple, yet very powerful caching framework for Ruby.
|
135
|
-
test_files:
|
136
|
-
|
137
|
-
- test/cacheable_test.rb
|
138
|
-
- test/cachetastic_unit_test.rb
|
139
|
-
- test/config.rb
|
140
|
-
- test/drb_adapter_test.rb
|
141
|
-
- test/file_adapter_test.rb
|
142
|
-
- test/memcache_adapter_test.rb
|
143
|
-
- test/test_helper.rb
|
121
|
+
test_files: []
|
122
|
+
|
data/bin/cachetastic_drb_server
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby
|
2
|
-
require 'thread'
|
3
|
-
require 'drb'
|
4
|
-
require 'singleton'
|
5
|
-
require 'optparse'
|
6
|
-
require 'optparse/time'
|
7
|
-
require 'ostruct'
|
8
|
-
|
9
|
-
# require the necessary gems:
|
10
|
-
require 'rubygems'
|
11
|
-
gem 'mack-facets'
|
12
|
-
require 'mack-facets'
|
13
|
-
gem 'configatron'
|
14
|
-
require 'configatron'
|
15
|
-
gem 'cachetastic'
|
16
|
-
require 'cachetastic'
|
17
|
-
|
18
|
-
$SAFE = 1
|
19
|
-
|
20
|
-
SERVER_OPTIONS = OpenStruct.new
|
21
|
-
SERVER_OPTIONS.host = "127.0.0.1"
|
22
|
-
SERVER_OPTIONS.port = "61676"
|
23
|
-
SERVER_OPTIONS.config_file = nil
|
24
|
-
SERVER_OPTIONS.verbose = false
|
25
|
-
SERVER_OPTIONS.really_verbose = false
|
26
|
-
|
27
|
-
opts = OptionParser.new do |opts|
|
28
|
-
|
29
|
-
opts.on("-h [HOST]") do |v|
|
30
|
-
SERVER_OPTIONS.host = v
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.on("-p [PORT]", Integer) do |v|
|
34
|
-
SERVER_OPTIONS.port = v
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on("-c [CONFIG_FILE]") do |v|
|
38
|
-
SERVER_OPTIONS.config_file = v
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on("-v") do |v|
|
42
|
-
SERVER_OPTIONS.verbose = true
|
43
|
-
end
|
44
|
-
|
45
|
-
opts.on("-rv") do |v|
|
46
|
-
SERVER_OPTIONS.verbose = true
|
47
|
-
SERVER_OPTIONS.really_verbose = true
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
opts.parse!(ARGV)
|
53
|
-
|
54
|
-
if SERVER_OPTIONS.config_file
|
55
|
-
configatron.configure_from_yaml(SERVER_OPTIONS.config_file)
|
56
|
-
end
|
57
|
-
|
58
|
-
module Cachetastic
|
59
|
-
module Drb
|
60
|
-
class Server
|
61
|
-
include Singleton
|
62
|
-
|
63
|
-
def initialize
|
64
|
-
DRb.start_service("druby://#{SERVER_OPTIONS.host}:#{SERVER_OPTIONS.port}", self)
|
65
|
-
puts "Cachetastic::Drb::Server listening for connection..."
|
66
|
-
DRb.thread.join
|
67
|
-
end # initialize
|
68
|
-
|
69
|
-
def get(ns, key)
|
70
|
-
puts "get: #{ns}.#{key}" if SERVER_OPTIONS.verbose
|
71
|
-
puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
|
72
|
-
value = cache_for_namespace(ns).get(key)
|
73
|
-
puts "\tvalue.class: #{value.class}" if SERVER_OPTIONS.verbose
|
74
|
-
value
|
75
|
-
end
|
76
|
-
|
77
|
-
def set(ns, key, value, expiry = 0)
|
78
|
-
puts "set: #{ns}.#{key}: #{value}" if SERVER_OPTIONS.verbose
|
79
|
-
cache_for_namespace(ns).set(key, value)
|
80
|
-
puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
|
81
|
-
value
|
82
|
-
end
|
83
|
-
|
84
|
-
def delete(ns, key, delay = 0)
|
85
|
-
puts "delete: #{ns}.#{key}" if SERVER_OPTIONS.verbose
|
86
|
-
cache_for_namespace(ns).delete(key, delay = 0)
|
87
|
-
puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
|
88
|
-
end
|
89
|
-
|
90
|
-
def expire_all(ns)
|
91
|
-
puts "expire_all: #{ns}" if SERVER_OPTIONS.verbose
|
92
|
-
instance_variable_set("@store_for_#{ns}", Cachetastic::Adapters::LocalMemory.new("store_for_#{ns}"))
|
93
|
-
end
|
94
|
-
|
95
|
-
def ping
|
96
|
-
true
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
def cache_for_namespace(ns)
|
101
|
-
# puts "@store_for_#{ns}"
|
102
|
-
c = instance_variable_get("@store_for_#{ns}")
|
103
|
-
if c.nil?
|
104
|
-
instance_variable_set("@store_for_#{ns}", Cachetastic::Adapters::LocalMemory.new("store_for_#{ns}"))
|
105
|
-
c = instance_variable_get("@store_for_#{ns}")
|
106
|
-
end
|
107
|
-
c
|
108
|
-
end
|
109
|
-
|
110
|
-
end # Server
|
111
|
-
end # Drb
|
112
|
-
end # Cachetastic
|
113
|
-
|
114
|
-
# let's start `er up!
|
115
|
-
Cachetastic::Drb::Server.instance
|