cachetastic 1.1.3 → 1.1.8

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 (110) hide show
  1. data/README +3 -1
  2. data/doc/classes/ActiveRecord/Base.html +22 -2
  3. data/doc/classes/ActiveRecord/Base.src/M000001.html +1 -1
  4. data/doc/classes/ActiveRecord/Base.src/M000002.html +1 -1
  5. data/doc/classes/ActiveRecord/Base.src/M000003.html +1 -1
  6. data/doc/classes/ActiveRecord/Base.src/M000004.html +1 -1
  7. data/doc/classes/ActiveRecord/Base.src/M000005.html +1 -1
  8. data/doc/classes/{Cachetastic/Stores.html → CGI/Session/CachetasticStore.html} +23 -14
  9. data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html +17 -6
  10. data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.src/{M000044.html → M000043.html} +1 -1
  11. data/doc/classes/Cachetastic/Caches/Base.html +148 -54
  12. data/doc/classes/Cachetastic/Caches/Base.src/{M000043.html → M000032.html} +4 -4
  13. data/doc/classes/Cachetastic/Caches/Base.src/M000033.html +14 -4
  14. data/doc/classes/Cachetastic/Caches/Base.src/M000034.html +9 -6
  15. data/doc/classes/Cachetastic/Caches/Base.src/M000035.html +5 -13
  16. data/doc/classes/Cachetastic/Caches/Base.src/M000036.html +5 -18
  17. data/doc/classes/Cachetastic/Caches/Base.src/M000037.html +4 -6
  18. data/doc/classes/Cachetastic/Caches/Base.src/M000038.html +4 -5
  19. data/doc/classes/Cachetastic/Caches/Base.src/M000039.html +4 -4
  20. data/doc/classes/Cachetastic/Caches/Base.src/M000040.html +4 -4
  21. data/doc/classes/Cachetastic/Caches/Base.src/M000041.html +4 -4
  22. data/doc/classes/Cachetastic/Caches/Base.src/M000042.html +14 -4
  23. data/doc/classes/Cachetastic/Caches/PageCache.html +8 -0
  24. data/doc/classes/Cachetastic/Caches/RailsSessionCache.html +6 -0
  25. data/doc/classes/Cachetastic/Connection.html +14 -14
  26. data/doc/classes/Cachetastic/Connection.src/M000044.html +18 -0
  27. data/doc/classes/Cachetastic/Connection.src/M000045.html +10 -4
  28. data/doc/classes/Cachetastic/Logger.html +5 -5
  29. data/doc/classes/Cachetastic/Stores/Base.html +68 -45
  30. data/doc/classes/Cachetastic/Stores/Base.src/{M000028.html → M000023.html} +1 -1
  31. data/doc/classes/Cachetastic/Stores/Base.src/{M000030.html → M000024.html} +1 -1
  32. data/doc/classes/Cachetastic/Stores/Base.src/{M000032.html → M000025.html} +1 -1
  33. data/doc/classes/Cachetastic/Stores/File.html +265 -0
  34. data/doc/classes/Cachetastic/Stores/File.src/M000026.html +18 -0
  35. data/doc/classes/Cachetastic/Stores/File.src/M000027.html +20 -0
  36. data/doc/classes/Cachetastic/Stores/File.src/M000028.html +19 -0
  37. data/doc/classes/Cachetastic/Stores/File.src/M000029.html +33 -0
  38. data/doc/classes/Cachetastic/Stores/File.src/M000030.html +21 -0
  39. data/doc/classes/Cachetastic/Stores/{LocalMemory.src/M000025.html → File.src/M000031.html} +3 -3
  40. data/doc/classes/Cachetastic/Stores/LocalMemory.html +41 -36
  41. data/doc/classes/Cachetastic/Stores/{Base.src/M000029.html → LocalMemory.src/M000017.html} +3 -3
  42. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000018.html +18 -0
  43. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000019.html +18 -0
  44. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000020.html +12 -4
  45. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000021.html +4 -4
  46. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000022.html +11 -4
  47. data/doc/classes/Cachetastic/Stores/Memcache.html +85 -59
  48. data/doc/classes/Cachetastic/Stores/Memcache.src/M000006.html +19 -0
  49. data/doc/classes/Cachetastic/Stores/{LocalMemory.src/M000024.html → Memcache.src/M000007.html} +3 -3
  50. data/doc/classes/Cachetastic/Stores/Memcache.src/M000008.html +18 -0
  51. data/doc/classes/Cachetastic/Stores/Memcache.src/M000009.html +4 -5
  52. data/doc/classes/Cachetastic/Stores/Memcache.src/M000010.html +4 -4
  53. data/doc/classes/Cachetastic/Stores/Memcache.src/M000011.html +4 -4
  54. data/doc/classes/Cachetastic/Stores/Memcache.src/M000012.html +10 -4
  55. data/doc/classes/Cachetastic/Stores/Memcache.src/M000013.html +5 -4
  56. data/doc/classes/Cachetastic/Stores/Memcache.src/M000014.html +6 -4
  57. data/doc/classes/Cachetastic/Stores/Memcache.src/M000015.html +6 -5
  58. data/doc/classes/Cachetastic/Stores/Memcache.src/M000016.html +9 -9
  59. data/doc/created.rid +1 -1
  60. data/doc/files/init_rb.html +111 -1
  61. data/doc/files/lib/caches/cachetastic_caches_base_rb.html +1 -1
  62. data/doc/files/lib/caches/cachetastic_caches_page_cache_rb.html +9 -1
  63. data/doc/files/lib/caches/cachetastic_caches_rails_session_cache_rb.html +7 -1
  64. data/doc/files/lib/cachetastic_connection_rb.html +1 -1
  65. data/doc/files/lib/cachetastic_rb.html +6 -2
  66. data/doc/files/lib/helpers/cachetastic_helpers_active_record_rb.html +1 -1
  67. data/doc/files/lib/rails_extensions/cachetastic_active_record_base_rb.html +1 -1
  68. data/doc/files/lib/rails_extensions/cgi_session_cachetastic_store_rb.html +1 -1
  69. data/doc/files/lib/stores/cachetastic_stores_base_rb.html +39 -1
  70. data/doc/{classes/ActiveRecord.html → files/lib/stores/cachetastic_stores_file_rb.html} +36 -22
  71. data/doc/files/lib/stores/cachetastic_stores_local_memory_rb.html +9 -1
  72. data/doc/files/lib/stores/cachetastic_stores_memcache_rb.html +27 -1
  73. data/doc/{classes/Cachetastic/Caches/ActiveRecord.html → files/lib/stores/cachetastic_stores_store_object_rb.html} +15 -19
  74. data/doc/fr_class_index.html +2 -8
  75. data/doc/fr_file_index.html +2 -0
  76. data/doc/fr_method_index.html +41 -42
  77. data/doc/index.html +2 -2
  78. data/init.rb +1 -0
  79. data/lib/caches/cachetastic_caches_base.rb +81 -18
  80. data/lib/caches/cachetastic_caches_page_cache.rb +4 -0
  81. data/lib/caches/cachetastic_caches_rails_session_cache.rb +1 -0
  82. data/lib/cachetastic.rb +10 -6
  83. data/lib/cachetastic_connection.rb +2 -2
  84. data/lib/helpers/cachetastic_helpers_active_record.rb +12 -1
  85. data/lib/rails_extensions/cachetastic_active_record_base.rb +10 -0
  86. data/lib/rails_extensions/cgi_session_cachetastic_store.rb +15 -10
  87. data/lib/stores/cachetastic_stores_base.rb +33 -13
  88. data/lib/stores/cachetastic_stores_file.rb +101 -0
  89. data/lib/stores/cachetastic_stores_local_memory.rb +6 -27
  90. data/lib/stores/cachetastic_stores_memcache.rb +24 -5
  91. data/lib/stores/cachetastic_stores_store_object.rb +28 -0
  92. data/lib/tasks/rubyforge_config.yml +1 -1
  93. metadata +28 -32
  94. data/doc/classes/Cachetastic/Caches.html +0 -114
  95. data/doc/classes/Cachetastic/Connection.src/M000046.html +0 -24
  96. data/doc/classes/Cachetastic/Helpers/ActiveRecord.html +0 -165
  97. data/doc/classes/Cachetastic/Helpers/ActiveRecord.src/M000006.html +0 -29
  98. data/doc/classes/Cachetastic/Helpers/ActiveRecord.src/M000007.html +0 -23
  99. data/doc/classes/Cachetastic/Helpers/ActiveRecord.src/M000008.html +0 -18
  100. data/doc/classes/Cachetastic/Helpers.html +0 -115
  101. data/doc/classes/Cachetastic/Stores/Base.src/M000031.html +0 -22
  102. data/doc/classes/Cachetastic/Stores/LocalMemory/StoreObject.html +0 -177
  103. data/doc/classes/Cachetastic/Stores/LocalMemory/StoreObject.src/M000026.html +0 -27
  104. data/doc/classes/Cachetastic/Stores/LocalMemory/StoreObject.src/M000027.html +0 -19
  105. data/doc/classes/Cachetastic/Stores/LocalMemory.src/M000023.html +0 -26
  106. data/doc/classes/Cachetastic/Stores/Memcache.src/M000017.html +0 -20
  107. data/doc/classes/Cachetastic/Stores/Memcache.src/M000018.html +0 -20
  108. data/doc/classes/Cachetastic/Stores/Memcache.src/M000019.html +0 -24
  109. data/doc/classes/Cachetastic.html +0 -119
  110. /data/doc/classes/Cachetastic/Logger.src/{M000047.html → M000046.html} +0 -0
@@ -20,53 +20,52 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Cachetastic/Caches/Base.html#M000033">all_registered_caches (Cachetastic::Caches::Base)</a><br />
24
- <a href="classes/Cachetastic/Helpers/ActiveRecord.html#M000007">cache (Cachetastic::Helpers::ActiveRecord)</a><br />
25
- <a href="classes/Cachetastic/Helpers/ActiveRecord.html#M000006">cache_class (Cachetastic::Helpers::ActiveRecord)</a><br />
26
- <a href="classes/Cachetastic/Caches/Base.html#M000041">cache_name (Cachetastic::Caches::Base)</a><br />
23
+ <a href="classes/Cachetastic/Caches/Base.html#M000032">all_registered_caches (Cachetastic::Caches::Base)</a><br />
24
+ <a href="classes/Cachetastic/Caches/Base.html#M000039">cache_name (Cachetastic::Caches::Base)</a><br />
27
25
  <a href="classes/ActiveRecord/Base.html#M000004">cache_self (ActiveRecord::Base)</a><br />
28
- <a href="classes/Cachetastic/Stores/Base.html#M000031">configure (Cachetastic::Stores::Base)</a><br />
29
- <a href="classes/Cachetastic/Stores/Base.html#M000030">debug? (Cachetastic::Stores::Base)</a><br />
30
- <a href="classes/Cachetastic/Caches/Base.html#M000037">delete (Cachetastic::Caches::Base)</a><br />
31
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000025">delete (Cachetastic::Stores::LocalMemory)</a><br />
32
- <a href="classes/Cachetastic/Stores/Memcache.html#M000011">delete (Cachetastic::Stores::Memcache)</a><br />
26
+ <a href="classes/Cachetastic/Caches/Base.html#M000042">calculate_expiry_time (Cachetastic::Caches::Base)</a><br />
27
+ <a href="classes/Cachetastic/Stores/Base.html#M000024">debug? (Cachetastic::Stores::Base)</a><br />
28
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000022">delete (Cachetastic::Stores::LocalMemory)</a><br />
29
+ <a href="classes/Cachetastic/Stores/File.html#M000031">delete (Cachetastic::Stores::File)</a><br />
30
+ <a href="classes/Cachetastic/Caches/Base.html#M000035">delete (Cachetastic::Caches::Base)</a><br />
31
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000008">delete (Cachetastic::Stores::Memcache)</a><br />
33
32
  <a href="classes/ActiveRecord/Base.html#M000002">delete_from_cache (ActiveRecord::Base)</a><br />
34
- <a href="classes/Cachetastic/Helpers/ActiveRecord.html#M000008">expire_all (Cachetastic::Helpers::ActiveRecord)</a><br />
35
- <a href="classes/Cachetastic/Caches/Base.html#M000038">expire_all (Cachetastic::Caches::Base)</a><br />
36
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000022">expire_all (Cachetastic::Stores::LocalMemory)</a><br />
37
- <a href="classes/Cachetastic/Stores/Memcache.html#M000013">expire_all (Cachetastic::Stores::Memcache)</a><br />
38
- <a href="classes/Cachetastic/Connection.html#M000046">get (Cachetastic::Connection)</a><br />
39
- <a href="classes/Cachetastic/Stores/Memcache.html#M000012">get (Cachetastic::Stores::Memcache)</a><br />
40
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000023">get (Cachetastic::Stores::LocalMemory)</a><br />
41
- <a href="classes/Cachetastic/Caches/Base.html#M000035">get (Cachetastic::Caches::Base)</a><br />
33
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000010">expire_all (Cachetastic::Stores::Memcache)</a><br />
34
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000019">expire_all (Cachetastic::Stores::LocalMemory)</a><br />
35
+ <a href="classes/Cachetastic/Caches/Base.html#M000036">expire_all (Cachetastic::Caches::Base)</a><br />
36
+ <a href="classes/Cachetastic/Stores/File.html#M000028">expire_all (Cachetastic::Stores::File)</a><br />
37
+ <a href="classes/Cachetastic/Stores/File.html#M000029">get (Cachetastic::Stores::File)</a><br />
38
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000009">get (Cachetastic::Stores::Memcache)</a><br />
39
+ <a href="classes/Cachetastic/Connection.html#M000045">get (Cachetastic::Connection)</a><br />
40
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000020">get (Cachetastic::Stores::LocalMemory)</a><br />
41
+ <a href="classes/Cachetastic/Caches/Base.html#M000033">get (Cachetastic::Caches::Base)</a><br />
42
42
  <a href="classes/ActiveRecord/Base.html#M000001">get_from_cache (ActiveRecord::Base)</a><br />
43
- <a href="classes/Cachetastic/Stores/Base.html#M000032">get_options (Cachetastic::Stores::Base)</a><br />
44
- <a href="classes/Cachetastic/Stores/Memcache.html#M000019">get_version (Cachetastic::Stores::Memcache)</a><br />
45
- <a href="classes/Cachetastic/Stores/Memcache.html#M000018">increment_version (Cachetastic::Stores::Memcache)</a><br />
46
- <a href="classes/Cachetastic/Caches/Base.html#M000034">inherited (Cachetastic::Caches::Base)</a><br />
47
- <a href="classes/Cachetastic/Stores/Memcache.html#M000014">inspect (Cachetastic::Stores::Memcache)</a><br />
48
- <a href="classes/Cachetastic/Caches/Base.html#M000043">logger (Cachetastic::Caches::Base)</a><br />
49
- <a href="classes/Cachetastic/Stores/Memcache.html#M000015">namespace (Cachetastic::Stores::Memcache)</a><br />
50
- <a href="classes/Cachetastic/Stores/Base.html#M000028">new (Cachetastic::Stores::Base)</a><br />
51
- <a href="classes/Cachetastic/Stores/LocalMemory/StoreObject.html#M000026">new (Cachetastic::Stores::LocalMemory::StoreObject)</a><br />
52
- <a href="classes/Cachetastic/Caches/Base/RegisteredCaches.html#M000044">new (Cachetastic::Caches::Base::RegisteredCaches)</a><br />
53
- <a href="classes/Cachetastic/Connection.html#M000045">new (Cachetastic::Connection)</a><br />
54
- <a href="classes/Cachetastic/Logger.html#M000047">new (Cachetastic::Logger)</a><br />
55
- <a href="classes/Cachetastic/Stores/Memcache.html#M000017">ns_versions (Cachetastic::Stores::Memcache)</a><br />
56
- <a href="classes/Cachetastic/Caches/Base.html#M000039">populate_all (Cachetastic::Caches::Base)</a><br />
57
- <a href="classes/Cachetastic/Stores/Memcache.html#M000010">set (Cachetastic::Stores::Memcache)</a><br />
58
- <a href="classes/Cachetastic/Caches/Base.html#M000036">set (Cachetastic::Caches::Base)</a><br />
59
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000024">set (Cachetastic::Stores::LocalMemory)</a><br />
43
+ <a href="classes/Cachetastic/Stores/Base.html#M000025">get_options (Cachetastic::Stores::Base)</a><br />
44
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000016">get_version (Cachetastic::Stores::Memcache)</a><br />
45
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000015">increment_version (Cachetastic::Stores::Memcache)</a><br />
46
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000011">inspect (Cachetastic::Stores::Memcache)</a><br />
47
+ <a href="classes/Cachetastic/Caches/Base.html#M000041">logger (Cachetastic::Caches::Base)</a><br />
48
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000013">namespace (Cachetastic::Stores::Memcache)</a><br />
49
+ <a href="classes/Cachetastic/Stores/Base.html#M000023">new (Cachetastic::Stores::Base)</a><br />
50
+ <a href="classes/Cachetastic/Connection.html#M000044">new (Cachetastic::Connection)</a><br />
51
+ <a href="classes/Cachetastic/Caches/Base/RegisteredCaches.html#M000043">new (Cachetastic::Caches::Base::RegisteredCaches)</a><br />
52
+ <a href="classes/Cachetastic/Logger.html#M000046">new (Cachetastic::Logger)</a><br />
53
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000014">ns_versions (Cachetastic::Stores::Memcache)</a><br />
54
+ <a href="classes/Cachetastic/Caches/Base.html#M000037">populate_all (Cachetastic::Caches::Base)</a><br />
55
+ <a href="classes/Cachetastic/Caches/Base.html#M000034">set (Cachetastic::Caches::Base)</a><br />
56
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000021">set (Cachetastic::Stores::LocalMemory)</a><br />
57
+ <a href="classes/Cachetastic/Stores/File.html#M000030">set (Cachetastic::Stores::File)</a><br />
58
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000007">set (Cachetastic::Stores::Memcache)</a><br />
60
59
  <a href="classes/ActiveRecord/Base.html#M000003">set_into_cache (ActiveRecord::Base)</a><br />
61
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000021">setup (Cachetastic::Stores::LocalMemory)</a><br />
62
- <a href="classes/Cachetastic/Stores/Memcache.html#M000009">setup (Cachetastic::Stores::Memcache)</a><br />
63
- <a href="classes/Cachetastic/Stores/LocalMemory/StoreObject.html#M000027">size (Cachetastic::Stores::LocalMemory::StoreObject)</a><br />
64
- <a href="classes/Cachetastic/Caches/Base.html#M000040">stats (Cachetastic::Caches::Base)</a><br />
65
- <a href="classes/Cachetastic/Caches/Base.html#M000042">store (Cachetastic::Caches::Base)</a><br />
60
+ <a href="classes/Cachetastic/Stores/File.html#M000027">setup (Cachetastic::Stores::File)</a><br />
61
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000006">setup (Cachetastic::Stores::Memcache)</a><br />
62
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000018">setup (Cachetastic::Stores::LocalMemory)</a><br />
63
+ <a href="classes/Cachetastic/Caches/Base.html#M000038">stats (Cachetastic::Caches::Base)</a><br />
64
+ <a href="classes/Cachetastic/Caches/Base.html#M000040">store (Cachetastic::Caches::Base)</a><br />
66
65
  <a href="classes/ActiveRecord/Base.html#M000005">uncache_self (ActiveRecord::Base)</a><br />
67
- <a href="classes/Cachetastic/Stores/Memcache.html#M000016">valid? (Cachetastic::Stores::Memcache)</a><br />
68
- <a href="classes/Cachetastic/Stores/LocalMemory.html#M000020">valid? (Cachetastic::Stores::LocalMemory)</a><br />
69
- <a href="classes/Cachetastic/Stores/Base.html#M000029">valid? (Cachetastic::Stores::Base)</a><br />
66
+ <a href="classes/Cachetastic/Stores/File.html#M000026">valid? (Cachetastic::Stores::File)</a><br />
67
+ <a href="classes/Cachetastic/Stores/LocalMemory.html#M000017">valid? (Cachetastic::Stores::LocalMemory)</a><br />
68
+ <a href="classes/Cachetastic/Stores/Memcache.html#M000012">valid? (Cachetastic::Stores::Memcache)</a><br />
70
69
  </div>
71
70
  </div>
72
71
  </body>
data/doc/index.html CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  <!--
7
7
 
8
- RDoc Documentation
8
+ Cachetastic-RDoc
9
9
 
10
10
  -->
11
11
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
12
  <head>
13
- <title>RDoc Documentation</title>
13
+ <title>Cachetastic-RDoc</title>
14
14
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
15
  </head>
16
16
  <frameset rows="20%, 80%">
data/init.rb CHANGED
@@ -0,0 +1 @@
1
+ # :include: README
@@ -1,9 +1,37 @@
1
1
  require 'singleton'
2
+ # When creating a new 'Cache' this class should be extended.
3
+ # Once extended you'll only need to override just the methods
4
+ # that are different for your cache.
5
+ # class MyAwesomeCache < Cachetastic::Caches::Base
6
+ # end
7
+ # MyAwesomeCache.set(1, "One")
8
+ # MyAwesomeCache.get(1) # => "One"
9
+ # MyAwesomeCache.update(1, "One!!")
10
+ # MyAwesomeCache.get(1) # => "One!!"
11
+ # MyAwesomeCache.delete(1)
12
+ # MyAwesomeCache.get(1) # => nil
13
+ #
14
+ # class MyAwesomeCache < Cachetastic::Caches::Base
15
+ # class << self
16
+ # def get(key)
17
+ # super(key) do
18
+ # set(key, key * 10)
19
+ # end
20
+ # end
21
+ # end
22
+ # end
23
+ # MyAwesomeCache.set(1, "One")
24
+ # MyAwesomeCache.get(1) # => "One"
25
+ # MyAwesomeCache.delete(1)
26
+ # MyAwesomeCache.get(1) # => 10
2
27
  class Cachetastic::Caches::Base
3
28
 
29
+ # Used to store a list of all the caches registered with the system.
30
+ # In order for a cache to be registered it must extend Cachetastic::Caches::Base.
4
31
  class RegisteredCaches
5
32
  include Singleton
6
33
 
34
+ # list of all caches registered with the system.
7
35
  attr_reader :list
8
36
 
9
37
  def initialize
@@ -16,22 +44,23 @@ class Cachetastic::Caches::Base
16
44
  # using class << self means we don't have to prefix each method with 'self.'
17
45
  class << self
18
46
 
47
+ # Returns a list of all registered caches in the system.
19
48
  def all_registered_caches
20
49
  RegisteredCaches.instance.list
21
50
  end
22
51
 
23
- def inherited(child)
24
- # puts "child: #{child.inspect}"
25
- all_registered_caches << child.to_s
26
- # puts "all_registered_caches: #{all_registered_caches.inspect}"
27
- end
28
-
52
+ # Returns an object from the cache for a given key.
53
+ # If the object comes back as nil and a block is given
54
+ # that block will be run and the results of the block
55
+ # will be run. This can be used to JIT caches, just make
56
+ # sure in the block to call the set method because the
57
+ # results of the block are not automatically cached.
29
58
  def get(key)
30
59
  res = nil
31
60
  do_with_logging(:get, key) do
32
61
  res = store.get(key.to_s)
33
62
  if res.nil?
34
- res = yield if block_given?
63
+ res = yield key if block_given?
35
64
  else
36
65
  res = unmarshall(res)
37
66
  end
@@ -40,18 +69,16 @@ class Cachetastic::Caches::Base
40
69
  res
41
70
  end
42
71
 
72
+ # Set a particular object info the cache for the given key.
73
+ # An optional third parameter sets the expiry time for the object in the cache.
74
+ # The default for this expiry is set as either 0, meaning it never expires, or
75
+ # if there's a default_expiry time set in the config file, that file will be
76
+ # used.
77
+ # If there is an expiry_swing set in the config file it will be +/- to the
78
+ # expiry time. See also: calculate_expiry_time
43
79
  def set(key, value, expiry = (store.all_options["default_expiry"] || 0))
44
80
  do_with_logging(:set, key) do
45
- exp_swing = store.all_options["expiry_swing"]
46
- if exp_swing
47
- swing = rand(exp_swing.to_i)
48
- case rand(2)
49
- when 0
50
- expiry = (expiry.to_i + swing)
51
- when 1
52
- expiry = (expiry.to_i - swing)
53
- end
54
- end
81
+ expiry = calculate_expiry_time(expiry)
55
82
  store.set(key.to_s, marshall(value), expiry.to_i)
56
83
  logger.info('', '', :expiry, cache_name, key, expiry.to_i)
57
84
  value
@@ -60,38 +87,74 @@ class Cachetastic::Caches::Base
60
87
 
61
88
  alias_method :put, :set
62
89
 
90
+ # Deletes an object from the cache. The optional delay parameter
91
+ # sets an offset, in seconds, for when the object should get deleted.
92
+ # The default of 0 means the object gets deleted right away.
63
93
  def delete(key, delay = 0)
64
94
  do_with_logging(:delete, key) do
65
95
  store.delete(key.to_s, delay)
66
96
  end
67
97
  end
68
98
 
99
+ # Expires all objects for this cache.
69
100
  def expire_all
70
101
  store.expire_all
71
102
  logger.info('', '', :expired, cache_name)
72
103
  end
73
104
 
105
+ # Raises a MethodNotImplemented exception. This method should be overridden
106
+ # in the child class to enable a populating the cache with all things that
107
+ # should be in there.
74
108
  def populate_all
75
109
  raise MethodNotImplemented.new("populate_all")
76
110
  end
77
111
 
112
+ # A convenience method that returns statistics for the underlying Cachetastic::Stores::Base for the cache.
78
113
  def stats
79
114
  store.stats
80
115
  end
81
116
 
117
+ # Returns a 'methodize' version of the cache's class name. This gets used in logging,
118
+ # namespacing, and as the key in the Cachetastic::Connection class.
119
+ # MyAwesomeCache.cache # => "my_awesome_cache"
120
+ # Cachetastic::Caches::Base # => "cachetastic_caches_base"
82
121
  def cache_name
83
122
  self.name.methodize
84
123
  end
85
-
124
+
125
+ # Returns the underlying Cachetastic::Stores::Base for this cache.
86
126
  def store
87
127
  cache_conn_instance.get(cache_name)
88
128
  end
89
129
 
130
+ # Returns the Cachetastic::Logger for the underlying Cachetastic::Stores::Base.
90
131
  def logger
91
132
  store.logger
92
133
  end
93
134
 
94
135
  private
136
+ # If the expiry time is set to 60 minutes and the expiry_swing time is set to
137
+ # 15 minutes, this method will return a number between 45 minutes and 75 minutes.
138
+ def calculate_expiry_time(expiry) # :doc:
139
+ exp_swing = store.all_options["expiry_swing"]
140
+ if exp_swing
141
+ swing = rand(exp_swing.to_i)
142
+ case rand(2)
143
+ when 0
144
+ expiry = (expiry.to_i + swing)
145
+ when 1
146
+ expiry = (expiry.to_i - swing)
147
+ end
148
+ end
149
+ expiry
150
+ end
151
+
152
+ def inherited(child)
153
+ # puts "child: #{child.inspect}"
154
+ all_registered_caches << child.to_s
155
+ # puts "all_registered_caches: #{all_registered_caches.inspect}"
156
+ end
157
+
95
158
  def marshall(value)
96
159
  return case store.all_options["marshall_method"]
97
160
  when "yaml"
@@ -1,2 +1,6 @@
1
+ # Used by the Mongrel Page Cache Handler gem for page caching.
2
+ # Future functionality may be added to this class to allow for
3
+ # things such as deleting a certain page/set of pages based on
4
+ # regex, etc...
1
5
  class Cachetastic::Caches::PageCache < Cachetastic::Caches::Base
2
6
  end
@@ -1,2 +1,3 @@
1
+ # Used for storing Rails sessions.
1
2
  class Cachetastic::Caches::RailsSessionCache < Cachetastic::Caches::Base
2
3
  end
data/lib/cachetastic.rb CHANGED
@@ -7,18 +7,20 @@ require 'yaml'
7
7
  require 'zlib'
8
8
  require 'pp'
9
9
 
10
- module Cachetastic
11
- module Caches
12
- module ActiveRecord
10
+ module Cachetastic #:nodoc:#
11
+ module Caches #:nodoc:#
12
+ module ActiveRecord #:nodoc:#
13
13
  end
14
14
  end
15
- module Stores
15
+ module Stores #:nodoc:#
16
16
  end
17
- module Helpers
18
- module ActiveRecord
17
+ module Helpers #:nodoc:#
18
+ module ActiveRecord #:nodoc:#
19
19
  end
20
20
  end
21
21
  end
22
+ module ActiveRecord #:nodoc:#
23
+ end
22
24
 
23
25
  require 'cachetastic_connection'
24
26
  require 'cachetastic_logger'
@@ -26,8 +28,10 @@ require 'caches/cachetastic_caches_base'
26
28
  require 'caches/cachetastic_caches_page_cache'
27
29
  require 'caches/cachetastic_caches_rails_session_cache'
28
30
  require 'stores/cachetastic_stores_base'
31
+ require 'stores/cachetastic_stores_store_object'
29
32
  require 'stores/cachetastic_stores_memcache'
30
33
  require 'stores/cachetastic_stores_local_memory'
34
+ require 'stores/cachetastic_stores_file'
31
35
  require 'helpers/cachetastic_helpers_active_record'
32
36
  require 'rails_extensions/cachetastic_active_record_base'
33
37
  require 'rails_extensions/cgi_session_cachetastic_store'
@@ -8,8 +8,8 @@ class Cachetastic::Connection
8
8
  self.connections = {}
9
9
  end
10
10
 
11
- # Takes the name of the cache and returns back the store object associated with the cache.
12
- # If the store object doesn't exist of the the store is no longer valid a new one is
11
+ # Takes the name of the cache, that's been methodized, and returns back the store object associated with the cache.
12
+ # If the store object doesn't exist or if the store is no longer valid (store.valid?) a new one is
13
13
  # created and returned.
14
14
  def get(name)
15
15
  name = name.to_sym
@@ -1,7 +1,12 @@
1
1
  module Cachetastic
2
2
  module Helpers
3
+ # These helpers get added to ActiveRecord at both class and instance levels.
3
4
  module ActiveRecord
4
5
 
6
+ # Returns the Cachetastic::Caches::Base object associated with the ActiveRecord model.
7
+ # If a cache hasn't been defined the one will be created on the fly.
8
+ # The cache for the ActiveRecord model is expected to be defined as:
9
+ # Cachetastic::Caches::ActiveRecord::MODEL_NAME_HERE
5
10
  def cache_class
6
11
  n = self.class.name
7
12
  n = self.name if n == "Class"
@@ -17,7 +22,12 @@ module Cachetastic
17
22
  c_name.constantize
18
23
  end
19
24
 
20
- def cache(key, expiry = 0)
25
+ # How much did I want to call this method cache?? It originally was that, but
26
+ # in Rails 2.0 they decided to use that name, so I had to rename this method.
27
+ # This method will attempt to get an object from the cache for a given key.
28
+ # If the object is nil and a block is given the block will be run, and the results
29
+ # of the block will be automatically cached.
30
+ def cacher(key, expiry = 0)
21
31
  cache_class.get(key) do
22
32
  if block_given?
23
33
  res = yield
@@ -26,6 +36,7 @@ module Cachetastic
26
36
  end
27
37
  end
28
38
 
39
+ # Expires all the objects associated with this ActiveRecord model's cache.
29
40
  def expire_all
30
41
  cache_class.expire_all
31
42
  end
@@ -5,6 +5,10 @@ class ActiveRecord::Base
5
5
  class << self
6
6
  include Cachetastic::Helpers::ActiveRecord # include helpers at class level
7
7
 
8
+ # Returns an object from the cache for a given key.
9
+ # If the object returned is nil and the self_populate parameter is true
10
+ # then the key will be used to try and find the object in the database,
11
+ # set the object into the cache, and then return the object.
8
12
  def get_from_cache(key, self_populate = false)
9
13
  res = cache_class.get(key)
10
14
  if res.nil? && self_populate
@@ -16,20 +20,26 @@ class ActiveRecord::Base
16
20
  res
17
21
  end
18
22
 
23
+ # Deletes an object from the cache for a given key.
19
24
  def delete_from_cache(key)
20
25
  cache_class.delete(key)
21
26
  end
22
27
 
28
+ # Sets an object into the cache for a given key.
23
29
  def set_into_cache(key, value, expiry = 0)
24
30
  cache_class.set(key, value, expiry)
25
31
  end
26
32
 
27
33
  end
28
34
 
35
+ # Unless the object is a new ActiveRecord object this method will store
36
+ # the object in the cache using the object's ID as the key.
29
37
  def cache_self
30
38
  cache_class.set(self.id, self) unless self.new_record?
31
39
  end
32
40
 
41
+ # Unless the object is a new ActiveRecord object this method will delete
42
+ # the object in the cache using the object's ID as the key.
33
43
  def uncache_self
34
44
  cache_class.delete(self.id) unless self.new_record?
35
45
  end
@@ -1,15 +1,20 @@
1
1
  require 'cgi'
2
2
  require 'cgi/session'
3
-
4
- class CGI #:nodoc:all
5
- class Session
3
+
4
+ class CGI #:nodoc:#
5
+ class Session #:nodoc:#
6
+ # Allows Rails to use Cachetastic for it's session store.
7
+ # The setting below needs to happen AFTER the gem has been required, obviously!
8
+ # In Rails 1.2.6 this is AFTER the initializer block.
9
+ # ActionController::Base.session_store = :cachetastic_store
6
10
  class CachetasticStore
7
-
11
+
12
+
8
13
  def check_id(id) #:nodoc:#
9
14
  /[^0-9a-zA-Z]+/ =~ id.to_s ? false : true
10
15
  end
11
16
 
12
- def initialize(session, options = {})
17
+ def initialize(session, options = {}) #:nodoc:#
13
18
  id = session.session_id
14
19
  unless check_id(id)
15
20
  raise ArgumentError, "session_id '%s' is invalid" % id
@@ -23,29 +28,29 @@ class CGI #:nodoc:all
23
28
  # Restore session state from the session's memcache entry.
24
29
  #
25
30
  # Returns the session state as a hash.
26
- def restore
31
+ def restore #:nodoc:#
27
32
  @session_data = Cachetastic::Caches::RailsSessionCache.get(@session_key) do
28
33
  {}
29
34
  end
30
35
  end
31
36
 
32
37
  # Save session state to the session's memcache entry.
33
- def update
38
+ def update #:nodoc:#
34
39
  Cachetastic::Caches::RailsSessionCache.set(@session_key, @session_data)
35
40
  end
36
41
 
37
42
  # Update and close the session's memcache entry.
38
- def close
43
+ def close #:nodoc:#
39
44
  update
40
45
  end
41
46
 
42
47
  # Delete the session's memcache entry.
43
- def delete
48
+ def delete #:nodoc:#
44
49
  Cachetastic::Caches::RailsSessionCache.delete(@session_key)
45
50
  @session_data = {}
46
51
  end
47
52
 
48
- def data
53
+ def data #:nodoc:#
49
54
  @session_data
50
55
  end
51
56
 
@@ -1,3 +1,17 @@
1
+ # This class is the interface used to develop stores for caches.
2
+ # Stores are where the data is actually held. These could be local memory,
3
+ # memcached, a database, the file system, etc...
4
+ # If you implement this API, then you should be able to plug in different
5
+ # stores for your caches without having to change any of your code.
6
+ #
7
+ # === Methods that need to be implemented:
8
+ # * setup - used to setup the implementation of the store.
9
+ # * set(key, object, expiry) - sets an object into the store using the given key and the expiry time.
10
+ # * get(key) - returns an object from the store for a given key.
11
+ # * delete(key, delay) - deletes an object from the store for a given key. If the store supports it, a delay can be used.
12
+ # * expire_all - expires all objects in the store for a given cache.
13
+ # * stats - returns statistics for the store.
14
+ # * valid? - used to test whether or not the store is still valid. If this returns false a new instance of the store is created by Cachetastic::Connection
1
15
  class Cachetastic::Stores::Base
2
16
 
3
17
  attr_reader :all_options
@@ -16,32 +30,29 @@ class Cachetastic::Stores::Base
16
30
  self.logger.debug(self.name, :options, self.all_options.inspect)
17
31
  end
18
32
  end
19
-
20
- def valid?
21
- false
22
- end
23
33
 
24
- [:setup, :set, :get, :delete, :expire_all, :stats].each do |meth|
34
+ [:setup, :set, :get, :delete, :expire_all, :stats, "valid?"].each do |meth|
25
35
  define_method(meth) do |*args|
26
36
  raise MethodNotImplemented.new(meth)
27
37
  end
28
38
  end
29
39
 
40
+ # Returns true/or falsed based on whether or not the debug setting is set to true in the
41
+ # configuration file. If the config setting is set, then false is returned.
30
42
  def debug?
31
43
  ivar_cache(:debug) do
32
44
  (self.all_options["debug"] == true || false)
33
45
  end
34
46
  end
35
47
 
36
- def configure
37
- @all_options = Cachetastic::Stores::Base.get_options(self.name)
38
- @store_options = (self.all_options["store_options"] || {})
39
- @servers = self.all_options["servers"]
40
- @logging = (self.all_options["logging"] || {})
41
- @logger = Cachetastic::Logger.new(self.logging, self.name)
42
- end
43
-
44
48
  class << self
49
+ # Merges options for the store in the configuration file with the cachetastic_default_options
50
+ # found in the configuration file, and returns the results.
51
+ # Options need to be specified in the configuration file as the methodized name of the store with
52
+ # _options attached at the end.
53
+ # Examples:
54
+ # Cachetastic::Caches::PageCache # => cachetastic_caches_page_cache_options
55
+ # MyAwesomeCache # => my_awesome_cache_options
45
56
  def get_options(name)
46
57
  options = app_config.cachetastic_default_options
47
58
  options.merge!(app_config.send(name.methodize + "_options") || {})
@@ -50,4 +61,13 @@ class Cachetastic::Stores::Base
50
61
  end
51
62
  end
52
63
 
64
+ private
65
+ def configure
66
+ @all_options = Cachetastic::Stores::Base.get_options(self.name)
67
+ @store_options = (self.all_options["store_options"] || {})
68
+ @servers = self.all_options["servers"]
69
+ @logging = (self.all_options["logging"] || {})
70
+ @logger = Cachetastic::Logger.new(self.logging, self.name)
71
+ end
72
+
53
73
  end