cachetastic 1.4.2 → 1.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 CHANGED
@@ -1,8 +1,3 @@
1
- =Gem Requirements:
2
- * Application Configuration
3
- * Ruby Extensions
4
- * Rails Extensions
5
-
6
1
  =Configuration:
7
2
 
8
3
  cachetastic_default_options:
data/lib/cachetastic.rb CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  require 'zlib'
7
7
  require 'pp'
8
8
  require 'drb'
9
+ require 'application_configuration'
9
10
  begin
10
11
  require 'memcache'
11
12
  rescue Exception => e
@@ -15,6 +16,7 @@ rescue Exception => e
15
16
  puts e.message
16
17
  end
17
18
 
19
+
18
20
  module Cachetastic #:nodoc:#
19
21
  module Caches #:nodoc:#
20
22
  module ActiveRecord #:nodoc:#
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ActiveRecordTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ ArAlbumCache.expire_all
7
+ Cachetastic::Caches::Base.expire_all
8
+ #FileUtils.rm_f(AR_DB, :verbose => true)# if File.exists?(AR_DB)
9
+ begin
10
+ ArMigration.down
11
+ rescue Exception => e
12
+ end
13
+ ArMigration.up
14
+ a = ArAlbum.create(:title => "Abbey Road", :artist => "The Beatles")
15
+ ArSong.create(:title => "Come Together", :album_id => a.id)
16
+ ArSong.create(:title => "Something", :album_id => a.id)
17
+ a = ArAlbum.create(:title => "Help!", :artist => "The Beatles")
18
+ ArSong.create(:title => "Yesterday", :album_id => a.id)
19
+ ArSong.create(:title => "Dizzy Miss Lizzie", :album_id => a.id)
20
+ end
21
+
22
+ def teardown
23
+ ArMigration.down
24
+ #FileUtils.rm_f(AR_DB, :verbose => true)# if File.exists?(AR_DB)
25
+ end
26
+
27
+ def test_album_cache
28
+ assert true
29
+ res = ArAlbumCache.get(:recent_albums, 5)
30
+ assert_not_nil res
31
+ assert res.is_a?(Array)
32
+ assert_equal 5, res.size
33
+ res.each do |r|
34
+ assert r.is_a?(ArAlbum)
35
+ end
36
+ end
37
+
38
+ def test_extensions
39
+ album = ArAlbum.find(1)
40
+ assert !Cachetastic::Caches::ActiveRecord.const_defined?("ArAlbumCache")
41
+ album.cache_self
42
+ assert Cachetastic::Caches::ActiveRecord.const_defined?("ArAlbumCache")
43
+ assert_equal album, Cachetastic::Caches::ActiveRecord::ArAlbumCache.get(1)
44
+
45
+ song = ArSong.find(1)
46
+ assert !Cachetastic::Caches::ActiveRecord.const_defined?("ArSongCache")
47
+ song.cache_self
48
+ assert Cachetastic::Caches::ActiveRecord.const_defined?("ArSongCache")
49
+ assert_equal song, Cachetastic::Caches::ActiveRecord::ArSongCache.get(1)
50
+ assert_equal album, Cachetastic::Caches::ActiveRecord::ArAlbumCache.get(1)
51
+
52
+ song.uncache_self
53
+ assert_nil Cachetastic::Caches::ActiveRecord::ArSongCache.get(1)
54
+
55
+ ac = ArAlbum.get_from_cache(1)
56
+ assert_not_nil ac
57
+ assert_equal album, ac
58
+
59
+ ArAlbum.delete_from_cache(1)
60
+ ac = ArAlbum.get_from_cache(1)
61
+ assert_nil ac
62
+
63
+ ac = ArAlbum.set_into_cache(1, album)
64
+ assert_not_nil ac
65
+ assert_equal album, ac
66
+
67
+ ac = ArAlbum.cacher(:foobar) do
68
+ ArAlbum.find(2)
69
+ end
70
+
71
+ assert_not_nil ac
72
+ assert_equal ArAlbum.find(2), ac
73
+
74
+ ac = ArAlbum.get_from_cache(:foobar)
75
+ assert_not_nil ac
76
+ assert_equal ArAlbum.find(2), ac
77
+
78
+ assert_equal [1,2,3,:yippie], ac.some_numbers([1,2,3])
79
+ assert_equal [1,2,3,:yippie], ArAlbum.get_from_cache(:some_numbers)
80
+ assert_equal [1,2,3,:yippie], ac.some_numbers([1,2,3,4,5,6])
81
+
82
+ ArAlbum.delete_from_cache(1)
83
+ ac = ArAlbum.get_from_cache(1)
84
+ assert_nil ac
85
+ ac = ArAlbum.get_from_cache(1, true)
86
+ assert_not_nil ac
87
+ end
88
+
89
+ end
@@ -0,0 +1,74 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class CachetasticUnitTest < Test::Unit::TestCase
4
+
5
+
6
+ def setup
7
+ Cachetastic::Caches::Base.expire_all
8
+ end
9
+
10
+ def test_class_cannot_be_instaniate
11
+ assert_raise(NoMethodError) { Cachetastic::Caches::Base.new }
12
+ end
13
+
14
+ def test_get
15
+ assert_nil Cachetastic::Caches::Base.get(:my_articles_test_get)
16
+ res = Cachetastic::Caches::Base.get(:my_articles_test_get) do
17
+ "hello mark"
18
+ end
19
+ assert_equal "hello mark", res
20
+ assert_nil Cachetastic::Caches::Base.get(:my_articles_test_get)
21
+
22
+ res = Cachetastic::Caches::Base.get(:my_articles_test_get) do
23
+ Cachetastic::Caches::Base.set(:my_articles_test_get, "hello mark")
24
+ end
25
+ assert_equal "hello mark", res
26
+ assert_not_nil Cachetastic::Caches::Base.get(:my_articles_test_get)
27
+ assert_equal "hello mark", Cachetastic::Caches::Base.get(:my_articles_test_get)
28
+ end
29
+
30
+ def test_set
31
+ assert true
32
+ Cachetastic::Caches::Base.set(:my_articles, [1, 2, 3], 15.minutes.from_now)
33
+ assert_equal [1,2,3], Cachetastic::Caches::Base.get(:my_articles)
34
+ end
35
+
36
+ def test_delete
37
+ test_set
38
+ Cachetastic::Caches::Base.delete(:my_articles)
39
+ assert_nil Cachetastic::Caches::Base.get(:my_articles)
40
+ end
41
+
42
+ def test_expire_all
43
+ a = [1,2,3,4,5,6,7,8,9,10]
44
+ Cachetastic::Caches::Base.set(:testing_expire_all, a)
45
+ assert_equal a, Cachetastic::Caches::Base.get(:testing_expire_all)
46
+ Cachetastic::Caches::Base.expire_all
47
+ assert_nil Cachetastic::Caches::Base.get(:testing_expire_all)
48
+ end
49
+
50
+ def test_local_memory_auto_expire
51
+ res = FooBarCache.get(:pickles)
52
+ assert_nil res
53
+ FooBarCache.set(:pickles, "are yummy")
54
+ res = FooBarCache.get(:pickles)
55
+ assert_not_nil res
56
+ assert_equal "are yummy", res
57
+ sleep(4)
58
+ res = FooBarCache.get(:pickles)
59
+ assert_nil res
60
+ end
61
+
62
+ def test_local_memory_delete
63
+ res = FooBarCache.get(:pickles)
64
+ assert_nil res
65
+ FooBarCache.set(:pickles, "are yummy")
66
+ res = FooBarCache.get(:pickles)
67
+ assert_not_nil res
68
+ assert_equal "are yummy", res
69
+ FooBarCache.delete(:pickles)
70
+ res = FooBarCache.get(:pickles)
71
+ assert_nil res
72
+ end
73
+
74
+ end
data/test/config.yml ADDED
@@ -0,0 +1,71 @@
1
+ # album_cache_options:
2
+ # servers:
3
+ # - 127.0.0.1:11211
4
+ #
5
+ # doctor_be_cache_options:
6
+ # adapter: drb
7
+ # store_options:
8
+ # host: "druby://127.0.0.1:61676"
9
+ #
10
+ # doctor_ce_cache_options:
11
+ # adapter: drb
12
+ # store_options:
13
+ # host: "druby://127.0.0.1:61676"
14
+ #
15
+ # cachetastic_caches_page_cache_options:
16
+ # default_expiry: <%= 60 * 60 %>
17
+ # expiry_swing: <%= 60 * 15 %>
18
+ #
19
+ # cachetastic_caches_rails_session_cache_options:
20
+ # adapter: local_memory
21
+ # store_options:
22
+ # dir: /cachetastic/
23
+ #
24
+ # memcache_benchmark_cache_options:
25
+ # debug: false
26
+ # adapter: memcache
27
+ # marshall_method: none
28
+ # store_options:
29
+ # c_threshold: 10_000
30
+ # compression: true
31
+ # debug: false
32
+ # readonly: false
33
+ # urlencode: false
34
+ #
35
+ my_file_store_cache_options:
36
+ debug: false
37
+ adapter: file
38
+ store_options:
39
+ dir: "/cachetastic/test"
40
+ #
41
+ # file_benchmark_cache_options:
42
+ # debug: false
43
+ # adapter: file
44
+ # store_options:
45
+ # dir: "/cachetastic/benchmark"
46
+ #
47
+ # local_memory_benchmark_cache_options:
48
+ # debug: false
49
+ # adapter: local_memory
50
+
51
+ cachetastic_default_options:
52
+ debug: true
53
+ adapter: local_memory
54
+ marshall_method: none
55
+ default_expiry: 2
56
+ # buffer: simple
57
+ # store_options:
58
+ # c_threshold: 10_000
59
+ # compression: true
60
+ # debug: false
61
+ # readonly: false
62
+ # urlencode: false
63
+ logging:
64
+ # logger_1:
65
+ # type: file
66
+ # file: log/memcached.log
67
+ logger_2:
68
+ type: console
69
+ level: debug
70
+ # servers:
71
+ # - 127.0.0.1:11211
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class DataMapperTest < Test::Unit::TestCase
4
+
5
+ def test_truth
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class FileAdapterTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ FileUtils.rm_rf(c_dir, :verbose => true)
7
+ end
8
+
9
+ def test_directory_created_if_it_doesnt_exist_on_new
10
+ assert !File.exists?(c_dir)
11
+ assert_nil MyFileStoreCache.get(1)
12
+ assert File.exists?(c_dir)
13
+ assert MyFileStoreCache.adapter.valid?
14
+ end
15
+
16
+ def test_invalid_if_directory_is_deleted
17
+ assert !File.exists?(c_dir)
18
+ assert_nil MyFileStoreCache.get(1)
19
+ assert File.exists?(c_dir)
20
+ FileUtils.rm_rf(c_dir, :verbose => true)
21
+ assert !Cachetastic::Connection.instance.connections[:my_file_store_cache].valid?
22
+ end
23
+
24
+ def test_expire_all
25
+ assert_nil MyFileStoreCache.get(1)
26
+ MyFileStoreCache.set(1, "hello")
27
+ assert_equal "hello", MyFileStoreCache.get(1)
28
+ assert_nil MyFileStoreCache.get(2)
29
+ MyFileStoreCache.set(2, [1,2,3,4])
30
+ assert_equal [1,2,3,4], MyFileStoreCache.get(2)
31
+ MyFileStoreCache.expire_all
32
+ assert_equal nil, MyFileStoreCache.get(1)
33
+ assert_equal nil, MyFileStoreCache.get(2)
34
+ end
35
+
36
+ def test_expiry
37
+ assert_nil MyFileStoreCache.get(1)
38
+ MyFileStoreCache.set(1, "hello", 1)
39
+ assert_equal "hello", MyFileStoreCache.get(1)
40
+ sleep(3)
41
+ assert_nil MyFileStoreCache.get(1)
42
+ end
43
+
44
+ private
45
+ def c_dir
46
+ "/cachetastic/test"
47
+ end
48
+
49
+ end
@@ -0,0 +1,90 @@
1
+ require "test/unit"
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "cachetastic")
3
+ require 'rubygems'
4
+ require 'mack_ruby_core_extensions'
5
+ require 'active_record'
6
+ require 'data_mapper'
7
+
8
+ # place common methods, assertions, and other type things in this file so
9
+ # other tests will have access to them.
10
+
11
+ app_config.load_file(File.join(File.dirname(__FILE__), "config.yml"))
12
+
13
+ class MyTempOptionsCache < Cachetastic::Caches::Base
14
+ end
15
+
16
+ class YourTempOptionsCache < Cachetastic::Caches::Base
17
+ end
18
+
19
+ class MyFileStoreCache < Cachetastic::Caches::Base
20
+ end
21
+
22
+ class FooBarCache < Cachetastic::Caches::Base
23
+ end
24
+
25
+ class ArAlbumCache < Cachetastic::Caches::Base
26
+ class << self
27
+ def get(key, num)
28
+ logger.info(key, num)
29
+ super(key) do
30
+ a = []
31
+ num.times do
32
+ a << ArAlbum.find(1)
33
+ end
34
+ set(key, a)
35
+ end
36
+ end # get
37
+ end # self
38
+ end # AlbumCache
39
+
40
+
41
+ #---- AR:
42
+ AR_DB = File.join(Dir.pwd, "ar_test.db")
43
+ puts "AR_DB: #{AR_DB}"
44
+ ActiveRecord::Base.establish_connection({:adapter => "sqlite3", :database => AR_DB})
45
+
46
+ class ArAlbum < ActiveRecord::Base
47
+ def some_numbers(arr)
48
+ cacher(:some_numbers) do
49
+ arr << :yippie
50
+ end
51
+ end
52
+ end
53
+ class ArSong < ActiveRecord::Base
54
+ end
55
+
56
+ class ArMigration < ActiveRecord::Migration
57
+ def self.up
58
+ create_table :ar_albums do |t|
59
+ t.column :title, :string
60
+ t.column :artist, :string
61
+ end
62
+ create_table :ar_songs do |t|
63
+ t.column :title, :string
64
+ t.column :album_id, :integer
65
+ end
66
+ end
67
+ def self.down
68
+ drop_table :ar_songs
69
+ drop_table :ar_albums
70
+ 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
+ end
metadata CHANGED
@@ -1,29 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
8
- autorequire:
9
- - cachetastic
8
+ autorequire: cachetastic
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2008-03-26 00:00:00 -04:00
12
+ date: 2008-06-03 00:00:00 -04:00
14
13
  default_executable:
15
- dependencies: []
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mack_ruby_core_extensions
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: application_configuration
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: A very simple, yet very powerful caching framework for Ruby.
34
+ email: mark@mackframework.com
35
+ executables: []
16
36
 
17
- description: "cachetastic was developed by: markbates"
18
- email:
19
- executables:
20
- - cachetastic_drb_server
21
37
  extensions: []
22
38
 
23
- extra_rdoc_files:
24
- - README
39
+ extra_rdoc_files: []
40
+
25
41
  files:
26
- - README
27
42
  - lib/adapters/cachetastic_adapters_base.rb
28
43
  - lib/adapters/cachetastic_adapters_drb.rb
29
44
  - lib/adapters/cachetastic_adapters_file.rb
@@ -43,17 +58,12 @@ files:
43
58
  - lib/helpers/cachetastic_helpers_active_record.rb
44
59
  - lib/rails_extensions/cachetastic_active_record_base.rb
45
60
  - lib/rails_extensions/cgi_session_cachetastic_store.rb
46
- - lib/tasks/rubyforge_config.yml
47
- has_rdoc: true
48
- homepage:
49
- post_install_message:
50
- rdoc_options:
51
- - --title
52
- - Cachetastic-RDoc
53
- - --main
54
61
  - README
55
- - --line-numbers
56
- - --inline-source
62
+ has_rdoc: false
63
+ homepage: http://www.mackframework.com
64
+ post_install_message:
65
+ rdoc_options: []
66
+
57
67
  require_paths:
58
68
  - lib
59
69
  - lib
@@ -71,10 +81,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
81
  version:
72
82
  requirements: []
73
83
 
74
- rubyforge_project: magrathea
75
- rubygems_version: 1.0.1
84
+ rubyforge_project:
85
+ rubygems_version: 1.1.1
76
86
  signing_key:
77
87
  specification_version: 2
78
- summary: cachetastic
79
- test_files: []
80
-
88
+ summary: A very simple, yet very powerful caching framework for Ruby.
89
+ test_files:
90
+ - test/active_record_test.rb
91
+ - test/cachetastic_unit_test.rb
92
+ - test/config.yml
93
+ - test/data_mapper_test.rb
94
+ - test/file_adapter_test.rb
95
+ - test/test_helper.rb
@@ -1,112 +0,0 @@
1
- require 'thread'
2
- require 'drb'
3
- require 'singleton'
4
- require 'optparse'
5
- require 'optparse/time'
6
- require 'ostruct'
7
-
8
- # require the necessary gems:
9
- require 'rubygems'
10
- gem 'ruby_extensions'
11
- require 'ruby_extensions'
12
- gem 'application_configuration'
13
- require 'application_configuration'
14
- gem 'cachetastic'
15
- require 'cachetastic'
16
-
17
- $SAFE = 1
18
-
19
- SERVER_OPTIONS = OpenStruct.new
20
- SERVER_OPTIONS.host = "127.0.0.1"
21
- SERVER_OPTIONS.port = "61676"
22
- SERVER_OPTIONS.config_file = nil
23
- SERVER_OPTIONS.verbose = false
24
- SERVER_OPTIONS.really_verbose = false
25
-
26
- opts = OptionParser.new do |opts|
27
-
28
- opts.on("-h [HOST]") do |v|
29
- SERVER_OPTIONS.host = v
30
- end
31
-
32
- opts.on("-p [PORT]", Integer) do |v|
33
- SERVER_OPTIONS.port = v
34
- end
35
-
36
- opts.on("-c [CONFIG_FILE]") do |v|
37
- SERVER_OPTIONS.config_file = v
38
- end
39
-
40
- opts.on("-v") do |v|
41
- SERVER_OPTIONS.verbose = true
42
- end
43
-
44
- opts.on("-rv") do |v|
45
- SERVER_OPTIONS.verbose = true
46
- SERVER_OPTIONS.really_verbose = true
47
- end
48
-
49
- end
50
-
51
- opts.parse!(ARGV)
52
-
53
- if SERVER_OPTIONS.config_file
54
- app_config.load_file(SERVER_OPTIONS.config_file)
55
- end
56
-
57
- module Cachetastic
58
- module Drb
59
- class Server
60
- include Singleton
61
-
62
- def initialize
63
- DRb.start_service("druby://#{SERVER_OPTIONS.host}:#{SERVER_OPTIONS.port}", self)
64
- puts "Cachetastic::Drb::Server listening for connection..."
65
- DRb.thread.join
66
- end # initialize
67
-
68
- def get(ns, key)
69
- puts "get: #{ns}.#{key}" if SERVER_OPTIONS.verbose
70
- puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
71
- cache_for_namespace(ns).get(key)
72
- end
73
-
74
- def set(ns, key, value, expiry = 0)
75
- puts "set: #{ns}.#{key}" if SERVER_OPTIONS.verbose
76
- cache_for_namespace(ns).set(key, value)
77
- puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
78
- value
79
- end
80
-
81
- def delete(ns, key, delay = 0)
82
- puts "delete: #{ns}.#{key}" if SERVER_OPTIONS.verbose
83
- cache_for_namespace(ns).delete(key, delay = 0)
84
- puts cache_for_namespace(ns).inspect if SERVER_OPTIONS.really_verbose
85
- end
86
-
87
- def expire_all(ns)
88
- puts "expire_all: #{ns}" if SERVER_OPTIONS.verbose
89
- instance_variable_set("@store_for_#{ns}", Cachetastic::Adapters::LocalMemory.new("store_for_#{ns}"))
90
- end
91
-
92
- def ping
93
- true
94
- end
95
-
96
- private
97
- def cache_for_namespace(ns)
98
- # puts "@store_for_#{ns}"
99
- c = instance_variable_get("@store_for_#{ns}")
100
- if c.nil?
101
- instance_variable_set("@store_for_#{ns}", Cachetastic::Adapters::LocalMemory.new("store_for_#{ns}"))
102
- c = instance_variable_get("@store_for_#{ns}")
103
- end
104
- c
105
- end
106
-
107
- end # Server
108
- end # Drb
109
- end # Cachetastic
110
-
111
- # let's start `er up!
112
- Cachetastic::Drb::Server.instance
@@ -1,5 +0,0 @@
1
- --- !ruby/object:RubyForgeConfig
2
- gem_name: cachetastic
3
- package: cachetastic
4
- project: magrathea
5
- version: 1.4.2