feedtools_ram_cache 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v1.0.2. Minor improvements in implementation and documentation.
2
+
1
3
  v1.0.1. Fixed typo in dependency list.
2
4
 
3
5
  v1.0. Initial release, tested to work with FeedTools 0.2.29.
data/README.textile CHANGED
@@ -18,8 +18,11 @@ h2. Usage
18
18
  The gem does not interfere with the FeedTools API. To enable RAM-based caching,
19
19
  require the gem and configure FeedTools to use it:
20
20
 
21
- bc. require 'feed_tools_ram_cache'
22
- FeedTools.configurations[:feed_cache] = 'RamFeedCache'
21
+ bc. # Configure FeedTools to use the RAM-backed cache.
22
+ require 'feed_tools_ram_cache'
23
+ FeedTools.configurations[:feed_cache] = FeedTools::RamFeedCache
24
+
25
+ In Rails, the code above can be placed in an initializer.
23
26
 
24
27
  h3. Serializing the Cache State
25
28
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{feedtools_ram_cache}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
9
- s.date = %q{2009-09-20}
9
+ s.date = %q{2009-09-21}
10
10
  s.description = %q{RAM-based cache for FeedTools.}
11
11
  s.email = %q{victor@zergling.net}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.textile", "lib/feed_tools_ram_cache.rb"]
@@ -40,6 +40,11 @@ class RamFeedCache
40
40
  @by_id, @by_href = nil, nil
41
41
  initialize_cache
42
42
  end
43
+
44
+ # The number of entries in the cache.
45
+ def self.length
46
+ @by_id.length
47
+ end
43
48
 
44
49
  # Fields required by FeedTools.
45
50
  #
@@ -71,6 +76,11 @@ class RamFeedCache
71
76
  true
72
77
  end
73
78
 
79
+ # Called by FeedTools.
80
+ def new_record?
81
+ @fields[:id].nil? ? true : false
82
+ end
83
+
74
84
  # Called by FeedTools to initialize the cache.
75
85
  def self.initialize_cache
76
86
  # NOTE: the FeedTools documentation says this will be called once. In fact,
data/test/cache_test.rb CHANGED
@@ -50,6 +50,11 @@ class CacheTest < Test::Unit::TestCase
50
50
  _check_state item
51
51
  end
52
52
 
53
+ def test_length
54
+ assert_equal 4, Cache.length, 'Incorrect number of cache entries'
55
+ end
56
+
57
+
53
58
  def test_find_by_id
54
59
  assert_equal nil, Cache.find_by_id(0), 'ID 0 should not exist'
55
60
  assert_equal 'google', Cache.find_by_id(1).href
@@ -80,22 +85,21 @@ class CacheTest < Test::Unit::TestCase
80
85
  end
81
86
 
82
87
  def test_state_storing
83
- #File.open('test/fixtures/unit.yml', 'w') do |f|
84
- # YAML.dump Cache.state, f
85
- #end
86
88
  assert_equal @golden_state, Cache.state
87
89
  end
88
90
 
89
91
  def test_clear
90
92
  Cache.clear
91
- assert_equal nil, Cache.find_by_id(1), 'Cache not deleted - found ID 1'
93
+ assert_equal 0, Cache.length, 'Cache not cleared -- found entries'
94
+ assert_equal nil, Cache.find_by_id(1), 'Cache not cleared - found ID 1'
92
95
  assert_equal nil, Cache.find_by_href('google'),
93
- 'Cache not deleted - found HREF google'
96
+ 'Cache not cleared - found HREF google'
94
97
  end
95
98
 
96
99
  def test_state_loading
97
100
  Cache.state = [{:id => 1}]
98
101
 
102
+ assert_equal 1, Cache.length, 'Cache state not reset, too many entries'
99
103
  assert_equal nil, Cache.find_by_id(2), 'Cache state not reset - found ID 2'
100
104
  assert_equal nil, Cache.find_by_href('google'),
101
105
  'Cache state not reset - found google'
@@ -105,6 +109,7 @@ class CacheTest < Test::Unit::TestCase
105
109
  Cache.clear
106
110
  Cache.state = @golden_state
107
111
 
112
+ test_length
108
113
  test_find_by_id
109
114
  test_find_by_href
110
115
  test_equality
@@ -11,7 +11,7 @@ require 'open-uri'
11
11
 
12
12
  class IntegrationTest < Test::Unit::TestCase
13
13
  def setup
14
- FeedTools.configurations[:feed_cache] = 'RamFeedCache'
14
+ FeedTools.configurations[:feed_cache] = FeedTools::RamFeedCache
15
15
  FeedTools::RamFeedCache.clear
16
16
  end
17
17
 
@@ -27,13 +27,23 @@ class IntegrationTest < Test::Unit::TestCase
27
27
 
28
28
  def _test_cache(uri)
29
29
  feed, cached_feed = nil, nil
30
- time = Benchmark.realtime { feed = FeedTools::Feed.open uri }
30
+ time = Benchmark.realtime do
31
+ feed = FeedTools::Feed.open(uri)
32
+ # NOTE: would like to include item instantiation, but it turns out parsing
33
+ # takes forever and dominates the running time
34
+ # feed.items.each { |item| item.description }
35
+ end
31
36
 
32
37
  # Make sure the cache's state is YAML-serializable
33
38
  yaml_state = FeedTools::RamFeedCache.state.to_yaml
34
39
  FeedTools::RamFeedCache.state = YAML.load yaml_state
35
40
 
36
- cached_time = Benchmark.realtime { cached_feed = FeedTools::Feed.open uri }
41
+ cached_time = Benchmark.realtime do
42
+ cached_feed = FeedTools::Feed.open uri
43
+ # NOTE: would like to include item instantiation, but it turns out parsing
44
+ # takes forever and dominates the running time
45
+ # cached_feed.items.each { |item| item.description }
46
+ end
37
47
 
38
48
  assert !cached_feed.live?, 'cached_feed is live?'
39
49
  assert_operator cached_time, :< , time / 3,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedtools_ram_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-20 00:00:00 -04:00
12
+ date: 2009-09-21 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency