cachetastic 1.7.4 → 2.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.
Files changed (76) hide show
  1. data/README +31 -44
  2. data/bin/cachetastic_drb_server +115 -0
  3. data/doc/classes/ActiveRecord/Base.html +16 -16
  4. data/doc/classes/CGI/Session/CachetasticStore.html +2 -2
  5. data/doc/classes/Cachetastic/Adapters/Base.html +74 -67
  6. data/doc/classes/Cachetastic/Adapters/Drb.html +11 -11
  7. data/doc/classes/Cachetastic/Adapters/File.html +5 -5
  8. data/doc/classes/Cachetastic/Adapters/FileBase.html +45 -45
  9. data/doc/classes/Cachetastic/Adapters/HtmlFile.html +23 -23
  10. data/doc/classes/Cachetastic/Adapters/LocalMemory.html +51 -51
  11. data/doc/classes/Cachetastic/Adapters/Memcache.html +89 -89
  12. data/doc/classes/Cachetastic/Cacheable.html +22 -22
  13. data/doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html +23 -23
  14. data/doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html +23 -23
  15. data/doc/classes/Cachetastic/Caches/Base.html +170 -199
  16. data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html +9 -9
  17. data/doc/classes/Cachetastic/Caches/MackSessionCache.html +2 -2
  18. data/doc/classes/Cachetastic/Caches/PageCache.html +2 -2
  19. data/doc/classes/Cachetastic/Caches/RailsSessionCache.html +9 -9
  20. data/doc/classes/Cachetastic/Connection.html +5 -5
  21. data/doc/classes/Cachetastic/Errors/UnsupportedAdapter.html +9 -9
  22. data/doc/classes/Cachetastic/Logger.html +23 -24
  23. data/doc/classes/Object.html +41 -3
  24. data/doc/created.rid +1 -1
  25. data/doc/files/README.html +33 -52
  26. data/doc/files/lib/{adapters/cachetastic_adapters_base_rb.html → cachetastic/adapters/base_rb.html} +6 -6
  27. data/doc/files/lib/{adapters/cachetastic_adapters_drb_rb.html → cachetastic/adapters/drb_rb.html} +5 -5
  28. data/doc/files/lib/{adapters/cachetastic_adapters_file_base_rb.html → cachetastic/adapters/file_base_rb.html} +5 -5
  29. data/doc/files/lib/{adapters/cachetastic_adapters_file_rb.html → cachetastic/adapters/file_rb.html} +5 -5
  30. data/doc/files/lib/{adapters/cachetastic_adapters_html_file_rb.html → cachetastic/adapters/html_file_rb.html} +5 -5
  31. data/doc/files/lib/{adapters/cachetastic_adapters_local_memory_rb.html → cachetastic/adapters/local_memory_rb.html} +5 -5
  32. data/doc/files/lib/{adapters/cachetastic_adapters_memcache_rb.html → cachetastic/adapters/memcache_rb.html} +5 -5
  33. data/doc/files/lib/{cachetastic_cacheable_rb.html → cachetastic/adapters/store_object_rb.html} +5 -5
  34. data/doc/files/lib/{ruby_extensions/object_rb.html → cachetastic/cacheable_rb.html} +4 -4
  35. data/doc/files/lib/{caches/cachetastic_caches_base_rb.html → cachetastic/caches/base_rb.html} +5 -5
  36. data/doc/files/lib/{cachetastic_connection_rb.html → cachetastic/caches/mack_session_cache_rb.html} +6 -6
  37. data/doc/files/lib/{caches/cachetastic_caches_page_cache_rb.html → cachetastic/caches/page_cache_rb.html} +5 -5
  38. data/doc/files/lib/{caches/cachetastic_caches_rails_session_cache_rb.html → cachetastic/caches/rails_session_cache_rb.html} +5 -5
  39. data/doc/files/lib/{caches/cachetastic_caches_mack_session_cache_rb.html → cachetastic/connection_rb.html} +5 -5
  40. data/doc/files/lib/{adapters/cachetastic_adapters_store_object_rb.html → cachetastic/errors/unsupported_adapter_rb.html} +5 -5
  41. data/doc/files/lib/{cachetastic_logger_rb.html → cachetastic/logger_rb.html} +5 -5
  42. data/doc/files/lib/{rails_extensions/cachetastic_active_record_base_rb.html → cachetastic/rails_extensions/active_record_base_rb.html} +5 -5
  43. data/doc/files/lib/{rails_extensions/cgi_session_cachetastic_store_rb.html → cachetastic/rails_extensions/cgi_session_store_rb.html} +5 -5
  44. data/doc/files/lib/cachetastic/ruby_extensions/object_rb.html +101 -0
  45. data/doc/files/lib/cachetastic_rb.html +34 -53
  46. data/doc/fr_file_index.html +19 -19
  47. data/doc/fr_method_index.html +63 -62
  48. data/lib/cachetastic.rb +35 -22
  49. data/lib/{adapters/cachetastic_adapters_base.rb → cachetastic/adapters/base.rb} +23 -30
  50. data/lib/{adapters/cachetastic_adapters_drb.rb → cachetastic/adapters/drb.rb} +2 -2
  51. data/lib/{adapters/cachetastic_adapters_file.rb → cachetastic/adapters/file.rb} +0 -0
  52. data/lib/{adapters/cachetastic_adapters_file_base.rb → cachetastic/adapters/file_base.rb} +1 -1
  53. data/lib/{adapters/cachetastic_adapters_html_file.rb → cachetastic/adapters/html_file.rb} +0 -0
  54. data/lib/{adapters/cachetastic_adapters_local_memory.rb → cachetastic/adapters/local_memory.rb} +0 -0
  55. data/lib/{adapters/cachetastic_adapters_memcache.rb → cachetastic/adapters/memcache.rb} +3 -3
  56. data/lib/{adapters/cachetastic_adapters_store_object.rb → cachetastic/adapters/store_object.rb} +0 -0
  57. data/lib/{cachetastic_cacheable.rb → cachetastic/cacheable.rb} +0 -0
  58. data/lib/{caches/cachetastic_caches_base.rb → cachetastic/caches/base.rb} +11 -13
  59. data/lib/{caches/cachetastic_caches_mack_session_cache.rb → cachetastic/caches/mack_session_cache.rb} +0 -0
  60. data/lib/{caches/cachetastic_caches_page_cache.rb → cachetastic/caches/page_cache.rb} +0 -0
  61. data/lib/{caches/cachetastic_caches_rails_session_cache.rb → cachetastic/caches/rails_session_cache.rb} +0 -0
  62. data/lib/{cachetastic_connection.rb → cachetastic/connection.rb} +1 -1
  63. data/lib/{errors/cachetastic_errors_unsupported_adapter.rb → cachetastic/errors/unsupported_adapter.rb} +0 -0
  64. data/lib/cachetastic/logger.rb +49 -0
  65. data/lib/{rails_extensions/cachetastic_active_record_base.rb → cachetastic/rails_extensions/active_record_base.rb} +0 -0
  66. data/lib/{rails_extensions/cgi_session_cachetastic_store.rb → cachetastic/rails_extensions/cgi_session_store.rb} +0 -0
  67. data/lib/{ruby_extensions → cachetastic/ruby_extensions}/object.rb +0 -0
  68. data/test/config.rb +30 -0
  69. data/test/drb_adapter_test.rb +14 -0
  70. data/test/memcache_adapter_test.rb +14 -0
  71. data/test/test_helper.rb +8 -22
  72. metadata +58 -47
  73. data/doc/files/lib/errors/cachetastic_errors_unsupported_adapter_rb.html +0 -101
  74. data/lib/cachetastic_logger.rb +0 -44
  75. data/test/config.yml +0 -71
  76. data/test/data_mapper_test.rb +0 -9
data/lib/cachetastic.rb CHANGED
@@ -6,17 +6,26 @@ require 'yaml'
6
6
  require 'zlib'
7
7
  require 'pp'
8
8
  require 'drb'
9
- # require 'mack_ruby_core_extensions'
10
- require 'application_configuration'
9
+ require 'configatron'
11
10
  begin
12
11
  require 'memcache'
13
12
  rescue Exception => e
14
13
  # if you don't have memcache installed, don't
15
14
  # blow up, print a message, and you can't use
16
15
  # the memcache adapter.
17
- puts "Warning: You don't have the memcache gem installed which means you can't use the Cachetastic::Adapters::Memcache adapter."
16
+ puts "CACHETASTIC: Warning: You don't have the memcache gem installed which means you can't use the Cachetastic::Adapters::Memcache adapter."
18
17
  end
19
18
 
19
+ class Object
20
+ # Uses <code>define_method</code> to create an empty for the method parameter defined.
21
+ # That method will then raise MethodNotImplemented. This is useful for creating interfaces
22
+ # and you want to stub out methods that others need to implement.
23
+ def self.needs_method(meth)
24
+ define_method(meth) do
25
+ raise NoMethodError.new("The interface you are using requires you define the following method '#{meth}'")
26
+ end
27
+ end
28
+ end
20
29
 
21
30
  module Cachetastic #:nodoc:#
22
31
  module Caches #:nodoc:#
@@ -31,26 +40,30 @@ end
31
40
  module ActiveRecord #:nodoc:#
32
41
  end
33
42
 
34
- home = File.dirname(__FILE__)
43
+ home = File.join(File.dirname(__FILE__), 'cachetastic')
44
+
45
+ require File.join(home, 'connection')
46
+ require File.join(home, 'logger')
47
+ require File.join(home, 'caches/base')
48
+ require File.join(home, 'caches/page_cache')
49
+ require File.join(home, 'caches/rails_session_cache')
50
+ require File.join(home, 'caches/mack_session_cache')
51
+ require File.join(home, 'errors/unsupported_adapter')
52
+ require File.join(home, 'adapters/base')
53
+ require File.join(home, 'adapters/store_object')
54
+ require File.join(home, 'adapters/memcache')
55
+ require File.join(home, 'adapters/local_memory')
56
+ require File.join(home, 'adapters/file_base')
57
+ require File.join(home, 'adapters/file')
58
+ require File.join(home, 'adapters/html_file')
59
+ require File.join(home, 'adapters/drb')
60
+ require File.join(home, 'cacheable')
61
+ require File.join(home, 'rails_extensions/active_record_base')
62
+ require File.join(home, 'rails_extensions/cgi_session_store')
35
63
 
36
- require File.join(home, 'cachetastic_connection')
37
- require File.join(home, 'cachetastic_logger')
38
- require File.join(home, 'caches/cachetastic_caches_base')
39
- require File.join(home, 'caches/cachetastic_caches_page_cache')
40
- require File.join(home, 'caches/cachetastic_caches_rails_session_cache')
41
- require File.join(home, 'caches/cachetastic_caches_mack_session_cache')
42
- require File.join(home, 'errors/cachetastic_errors_unsupported_adapter')
43
- require File.join(home, 'adapters/cachetastic_adapters_base')
44
- require File.join(home, 'adapters/cachetastic_adapters_store_object')
45
- require File.join(home, 'adapters/cachetastic_adapters_memcache')
46
- require File.join(home, 'adapters/cachetastic_adapters_local_memory')
47
- require File.join(home, 'adapters/cachetastic_adapters_file_base')
48
- require File.join(home, 'adapters/cachetastic_adapters_file')
49
- require File.join(home, 'adapters/cachetastic_adapters_html_file')
50
- require File.join(home, 'adapters/cachetastic_adapters_drb')
51
- require File.join(home, 'cachetastic_cacheable')
52
- require File.join(home, 'rails_extensions/cachetastic_active_record_base')
53
- require File.join(home, 'rails_extensions/cgi_session_cachetastic_store')
64
+ configatron.cachetastic_default_options.set_default(:debug, false)
65
+ configatron.cachetastic_default_options.set_default(:adapter, :local_memory)
66
+ configatron.cachetastic_default_options.set_default(:logger, ::Logger.new(STDOUT))
54
67
 
55
68
  #--
56
69
  # http://rdoc.sourceforge.net/doc/index.html
@@ -14,35 +14,35 @@
14
14
  # * valid? - used to test whether or not the store is still valid. If this returns false a new instance of the adapter is created by Cachetastic::Connection
15
15
  class Cachetastic::Adapters::Base
16
16
 
17
- attr_reader :all_options
18
- attr_reader :store_options
19
- attr_reader :servers
17
+ # attr_reader :all_options
18
+ # attr_reader :store_options
19
+ # attr_reader :servers
20
20
  attr_reader :name
21
- attr_reader :logging
21
+ # attr_reader :logging
22
22
  attr_reader :logger
23
23
 
24
24
  def initialize(name)
25
25
  @name = name
26
- configure
26
+ @logger = Cachetastic::Logger.new(configuration.retrieve(:logger, ::Logger.new(STDOUT)))
27
27
  setup
28
28
  if self.debug?
29
29
  self.logger.debug(self.name, :self, self.inspect)
30
- self.logger.debug(self.name, :options, self.all_options.inspect)
31
30
  end
32
31
  end
33
32
 
34
- # foo bar
35
- [:setup, :set, :get, :delete, :expire_all, :stats, "valid?"].each do |meth|
36
- define_method(meth) do |*args|
37
- raise MethodNotImplemented.new(meth)
38
- end
39
- end
33
+ needs_method :setup
34
+ needs_method :set
35
+ needs_method :get
36
+ needs_method :delete
37
+ needs_method :expire_all
38
+ needs_method :stats
39
+ needs_method :valid?
40
40
 
41
41
  # Returns true/or falsed based on whether or not the debug setting is set to true in the
42
42
  # configuration file. If the config setting is set, then false is returned.
43
43
  def debug?
44
44
  ivar_cache(:debug) do
45
- (self.all_options["debug"] == true || false)
45
+ configuration.retrieve(:debug, false)
46
46
  end
47
47
  end
48
48
 
@@ -57,29 +57,22 @@ class Cachetastic::Adapters::Base
57
57
  puts s
58
58
  end
59
59
 
60
+ def configuration
61
+ Cachetastic::Adapters::Base.configuration(self.name)
62
+ end
63
+
60
64
  class << self
61
- # Merges options for the store in the configuration file with the cachetastic_default_options
62
- # found in the configuration file, and returns the results.
63
- # Options need to be specified in the configuration file as the methodized name of the cache with
65
+ # Returns either the options
66
+ # Options need to be specified in configatrion as the methodized name of the cache with
64
67
  # _options attached at the end.
65
68
  # Examples:
66
69
  # Cachetastic::Caches::PageCache # => cachetastic_caches_page_cache_options
67
70
  # MyAwesomeCache # => my_awesome_cache_options
68
- def get_options(name)
69
- options = (app_config.cachetastic_default_options || {})
70
- options = {"adapter" => "local_memory"}.merge(options)
71
- options = options.merge(app_config.send(name.methodize + "_options") || {})
72
- options
71
+ def configuration(name)
72
+ name = "#{name}_options"
73
+ conf = configatron.retrieve(name, configatron.cachetastic_default_options)
74
+ conf
73
75
  end
74
76
  end
75
77
 
76
- private
77
- def configure
78
- @all_options = Cachetastic::Adapters::Base.get_options(self.name)
79
- @store_options = (self.all_options["store_options"] || {})
80
- @servers = self.all_options["servers"]
81
- @logging = (self.all_options["logging"] || {})
82
- @logger = Cachetastic::Logger.new(self.logging, self.name)
83
- end
84
-
85
78
  end
@@ -18,8 +18,8 @@ class Cachetastic::Adapters::Drb < Cachetastic::Adapters::Base
18
18
  end
19
19
 
20
20
  def setup
21
- self.all_options["marshall_method"] = "ruby"
22
- self.drb_store = DRbObject.new_with_uri(self.store_options["host"])
21
+ # self.all_options["marshall_method"] = "ruby"
22
+ self.drb_store = DRbObject.new_with_uri(configuration.servers)
23
23
  end
24
24
 
25
25
  def expire_all
@@ -6,7 +6,7 @@ class Cachetastic::Adapters::FileBase < Cachetastic::Adapters::Base
6
6
  attr_reader :hashed_keys
7
7
 
8
8
  def setup
9
- @directory = File.join(self.store_options["dir"], self.name.to_s)
9
+ @directory = File.join(self.configuration.store_options.dir, self.name.to_s)
10
10
  FileUtils.mkdir_p(self.directory, :verbose => self.debug?)
11
11
  @hashed_keys = {}
12
12
  end
@@ -20,7 +20,7 @@
20
20
  class Cachetastic::Adapters::Memcache < Cachetastic::Adapters::Base
21
21
 
22
22
  def setup
23
- self.conn = MemCache.new(self.servers, self.store_options.merge({:namespace => self.namespace}))
23
+ self.conn = MemCache.new(configuration.servers, configuration.store_options.to_hash.merge({:namespace => self.namespace}))
24
24
  self.version = self.get_version(self.name)
25
25
  end
26
26
 
@@ -71,7 +71,7 @@ class Cachetastic::Adapters::Memcache < Cachetastic::Adapters::Base
71
71
  end
72
72
  end
73
73
  if memcached_tool_found
74
- app_config.memcache_servers.each do |server|
74
+ configuration.memcache_servers.each do |server|
75
75
  puts `memcached_tool #{server}`
76
76
  end
77
77
  end
@@ -91,7 +91,7 @@ class Cachetastic::Adapters::Memcache < Cachetastic::Adapters::Base
91
91
 
92
92
  def ns_versions
93
93
  ivar_cache do
94
- ns_conn = MemCache.new(self.servers, self.store_options.merge({:namespace => :namespace_versions}))
94
+ ns_conn = MemCache.new(configuration.servers, configuration.store_options.to_hash.merge({:namespace => :namespace_versions}))
95
95
  end
96
96
  end
97
97
 
@@ -91,7 +91,7 @@ class Cachetastic::Caches::Base
91
91
  # used.
92
92
  # If there is an expiry_swing set in the config file it will be +/- to the
93
93
  # expiry time. See also: calculate_expiry_time
94
- def set(key, value, expiry = (adapter.all_options["default_expiry"] || 0))
94
+ def set(key, value, expiry = adapter.configuration.retrieve(:default_expiry, 0))
95
95
  do_with_logging(:set, key) do
96
96
  expiry = calculate_expiry_time(expiry)
97
97
  adapter.set(key.to_s, marshall(value), expiry.to_i)
@@ -120,9 +120,7 @@ class Cachetastic::Caches::Base
120
120
  # Raises a MethodNotImplemented exception. This method should be overridden
121
121
  # in the child class to enable a populating the cache with all things that
122
122
  # should be in there.
123
- def populate_all
124
- raise MethodNotImplemented.new("populate_all")
125
- end
123
+ needs_method :populate_all
126
124
 
127
125
  # A convenience method that returns statistics for the underlying Cachetastic::Adapters::Base for the cache.
128
126
  def stats
@@ -166,10 +164,10 @@ class Cachetastic::Caches::Base
166
164
 
167
165
  def marshall(value)
168
166
  return value if value.nil?
169
- return case adapter.all_options["marshall_method"]
170
- when "yaml"
167
+ return case adapter.configuration.retrieve(:marshall_method, :none).to_sym
168
+ when :yaml
171
169
  YAML.dump(value)
172
- when "ruby"
170
+ when :ruby
173
171
  Marshal.dump(value)
174
172
  else
175
173
  value
@@ -178,10 +176,10 @@ class Cachetastic::Caches::Base
178
176
 
179
177
  def unmarshall(value)
180
178
  return value if value.nil?
181
- return case adapter.all_options["marshall_method"]
182
- when "yaml"
179
+ return case adapter.configuration.retrieve(:marshall_method, :none).to_sym
180
+ when :yaml
183
181
  YAML.load(value)
184
- when "ruby"
182
+ when :ruby
185
183
  Marshal.load(value)
186
184
  else
187
185
  value
@@ -192,8 +190,8 @@ class Cachetastic::Caches::Base
192
190
  # If the expiry time is set to 60 minutes and the expiry_swing time is set to
193
191
  # 15 minutes, this method will return a number between 45 minutes and 75 minutes.
194
192
  def calculate_expiry_time(expiry) # :doc:
195
- exp_swing = adapter.all_options["expiry_swing"]
196
- if exp_swing
193
+ exp_swing = adapter.configuration.retrieve(:expiry_swing, 0)
194
+ if exp_swing && exp_swing != 0
197
195
  swing = rand(exp_swing.to_i)
198
196
  case rand(2)
199
197
  when 0
@@ -232,7 +230,7 @@ class Cachetastic::Caches::Base
232
230
 
233
231
  # make sure people can't instaniate this object!
234
232
  def new(*args)
235
- raise MethodNotImplemented.new("You can not instaniate this class!")
233
+ raise NoMethodError.new("You can not instaniate this class!")
236
234
  end
237
235
 
238
236
  end
@@ -15,7 +15,7 @@ class Cachetastic::Connection
15
15
  name = name.to_sym
16
16
  conn = self.connections[name]
17
17
  return conn if conn && conn.valid?
18
- adapter = Cachetastic::Adapters::Base.get_options(name)["adapter"].camelcase
18
+ adapter = Cachetastic::Adapters::Base.configuration(name).adapter.to_s.camelcase
19
19
  conn = "Cachetastic::Adapters::#{adapter}".constantize.new(name)
20
20
  self.connections[name.to_sym] = conn
21
21
  return conn
@@ -0,0 +1,49 @@
1
+ # This class handles logging for the caches and their adapters.
2
+ class Cachetastic::Logger
3
+
4
+ # attr_accessor :options
5
+ # attr_accessor :cache_name
6
+ attr_accessor :loggers
7
+
8
+ def initialize(loggers)
9
+ @loggers = [loggers].flatten
10
+ # self.options = options
11
+ # self.cache_name = cache_name
12
+ # self.options.each_pair do |n, opts|
13
+ # opts["level"] = (opts["level"] ||= "info").to_sym
14
+ # end
15
+ end
16
+
17
+ LOG_LEVELS = [:fatal, :error, :warn, :info, :debug]
18
+
19
+ LOG_LEVELS.each do |level|
20
+ define_method(level) do |*args|
21
+ lm = "[CACHE] [#{level.to_s.upcase}]\t#{Time.now.strftime("%m/%d/%y %H:%M:%S")}"
22
+ exs = []
23
+ args.each do |arg|
24
+ if arg.is_a?(Exception)
25
+ exs << arg
26
+ continue
27
+ 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
+ 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
+ end
47
+ end
48
+
49
+ end
data/test/config.rb ADDED
@@ -0,0 +1,30 @@
1
+ configatron.my_file_store_cache_options.debug = false
2
+ configatron.my_file_store_cache_options.adapter = :file
3
+ configatron.my_file_store_cache_options.store_options.dir = '/cachetastic/test'
4
+ configatron.my_file_store_cache_options.logger = Logger.new(STDOUT)
5
+
6
+ configatron.cachetastic_default_options.debug = false
7
+ configatron.cachetastic_default_options.adapter = :local_memory
8
+ configatron.cachetastic_default_options.marshall_method = :none
9
+ configatron.cachetastic_default_options.default_expiry = 2
10
+ log = Logger.new(STDOUT)
11
+ log.level = Logger::DEBUG
12
+ configatron.cachetastic_default_options.logger = log
13
+
14
+ configatron.young_mc_cache_options.debug = true
15
+ configatron.young_mc_cache_options.adapter = :memcache
16
+ configatron.young_mc_cache_options.default_expiry = 2
17
+ configatron.young_mc_cache_options.logger = Logger.new(STDOUT)
18
+ configatron.young_mc_cache_options.servers = "127.0.0.1:11211"
19
+ configatron.young_mc_cache_options.store_options.c_threshold = "10_000"
20
+ configatron.young_mc_cache_options.store_options.compression = true
21
+ configatron.young_mc_cache_options.store_options.debug = false
22
+ configatron.young_mc_cache_options.readonly = false
23
+ configatron.young_mc_cache_options.urlencode = false
24
+
25
+ configatron.dr_bob_cache_options.debug = true
26
+ configatron.dr_bob_cache_options.adapter = :drb
27
+ configatron.dr_bob_cache_options.default_expiry = 2
28
+ configatron.dr_bob_cache_options.logger = Logger.new(STDOUT)
29
+ configatron.dr_bob_cache_options.servers = "druby://127.0.0.1:61676"
30
+ configatron.dr_bob_cache_options.marshall_method = :ruby
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class DrbAdapterTest < Test::Unit::TestCase
4
+
5
+ def test_drb_adapter
6
+ assert_nil DrBobCache.get(1)
7
+ assert DrBobCache.adapter.valid?
8
+ DrBobCache.set(1, :one)
9
+ assert_equal :one, DrBobCache.get(1)
10
+ DrBobCache.expire_all
11
+ assert_nil DrBobCache.get(1)
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class MemcacheAdapterTest < Test::Unit::TestCase
4
+
5
+ def test_memcache_adapter
6
+ assert_nil YoungMcCache.get(1)
7
+ assert YoungMcCache.adapter.valid?
8
+ YoungMcCache.set(1, :one)
9
+ assert_equal :one, YoungMcCache.get(1)
10
+ YoungMcCache.expire_all
11
+ assert_nil YoungMcCache.get(1)
12
+ end
13
+
14
+ end
data/test/test_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  require "test/unit"
2
2
  require File.join(File.dirname(__FILE__), "..", "lib", "cachetastic")
3
3
  require 'rubygems'
4
- require 'mack_ruby_core_extensions'
4
+ require 'mack-facets'
5
5
  require 'active_record'
6
- require 'data_mapper'
7
6
 
8
7
  # place common methods, assertions, and other type things in this file so
9
8
  # other tests will have access to them.
10
9
 
11
- app_config.load_file(File.join(File.dirname(__FILE__), "config.yml"))
10
+ require File.join(File.dirname(__FILE__), "config")
12
11
 
13
12
  class MyTempOptionsCache < Cachetastic::Caches::Base
14
13
  end
@@ -37,6 +36,12 @@ class ArAlbumCache < Cachetastic::Caches::Base
37
36
  end # self
38
37
  end # AlbumCache
39
38
 
39
+ class YoungMcCache < Cachetastic::Caches::Base
40
+ end
41
+
42
+ class DrBobCache < Cachetastic::Caches::Base
43
+ end
44
+
40
45
 
41
46
  #---- AR:
42
47
  AR_DB = File.join(Dir.pwd, "ar_test.db")
@@ -68,23 +73,4 @@ class ArMigration < ActiveRecord::Migration
68
73
  drop_table :ar_songs
69
74
  drop_table :ar_albums
70
75
  end
71
- end
72
-
73
- #---- DB:
74
- DM_DB = File.join(File.dirname(__FILE__), "dm_test.db")
75
- DataMapper::Database.setup({:adapter => "sqlite3", :database => DM_DB})
76
-
77
- class DmAlbum < DataMapper::Base
78
- property :title, :string
79
- property :artist, :string
80
- def some_numbers(arr)
81
- cacher(:some_numbers) do
82
- arr << :yippie
83
- end
84
- end
85
- end
86
-
87
- class DmSong < DataMapper::Base
88
- property :title, :string
89
- property :album_id, :integer
90
76
  end