Class: ItemCache
- Inherits:
-
Object
- Object
- ItemCache
- Defined in:
- lib/feed2imap/cache.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#commit_cache(id) ⇒ Object
Commit changes to the cache.
-
#fetch_failed(id) ⇒ Object
Fetching failure.
-
#get_last_check(id) ⇒ Object
Get the last time the cache was updated.
-
#get_new_items(id, items, always_new = false, ignore_hash = false) ⇒ Object
Returns the really new items amongst items.
-
#initialize(debug = false) ⇒ ItemCache
constructor
A new instance of ItemCache.
-
#load(io) ⇒ Object
Load the cache from an IO stream.
-
#nbchannels ⇒ Object
Return the number of channels in the cache.
-
#nbitems ⇒ Object
Return the number of items in the cache.
-
#parse_failed(id) ⇒ Object
Parsing failure.
-
#save(io) ⇒ Object
Save the cache to an IO stream.
-
#set_last_check(id, time) ⇒ Object
Get the last time the cache was updated.
Constructor Details
#initialize(debug = false) ⇒ ItemCache
Returns a new instance of ItemCache.
29 30 31 32 33 34 |
# File 'lib/feed2imap/cache.rb', line 29 def initialize(debug = false) @channels = {} @@cacheidx = 0 $updateddebug = debug self end |
Class Method Details
.getindex ⇒ Object
108 109 110 111 112 |
# File 'lib/feed2imap/cache.rb', line 108 def ItemCache.getindex i = @@cacheidx @@cacheidx += 1 i end |
Instance Method Details
#commit_cache(id) ⇒ Object
Commit changes to the cache
48 49 50 51 |
# File 'lib/feed2imap/cache.rb', line 48 def commit_cache(id) @channels[id] ||= CachedChannel::new @channels[id].commit end |
#fetch_failed(id) ⇒ Object
Fetching failure. returns number of failures
69 70 71 |
# File 'lib/feed2imap/cache.rb', line 69 def fetch_failed(id) @channels[id].fetch_failed end |
#get_last_check(id) ⇒ Object
Get the last time the cache was updated
54 55 56 57 |
# File 'lib/feed2imap/cache.rb', line 54 def get_last_check(id) @channels[id] ||= CachedChannel::new @channels[id].lastcheck end |
#get_new_items(id, items, always_new = false, ignore_hash = false) ⇒ Object
Returns the really new items amongst items
37 38 39 40 41 42 43 44 45 |
# File 'lib/feed2imap/cache.rb', line 37 def get_new_items(id, items, always_new = false, ignore_hash = false) if $updateddebug puts "=======================================================" puts "GET_NEW_ITEMS FOR #{id}... (#{Time::now})" end @channels[id] ||= CachedChannel::new @channels[id].parsefailures = 0 return @channels[id].get_new_items(items, always_new, ignore_hash) end |
#load(io) ⇒ Object
Load the cache from an IO stream
80 81 82 83 84 85 86 87 |
# File 'lib/feed2imap/cache.rb', line 80 def load(io) begin @@cacheidx, @channels = Marshal.load(io) rescue @channels = Marshal.load(io) @@cacheidx = 0 end end |
#nbchannels ⇒ Object
Return the number of channels in the cache
95 96 97 |
# File 'lib/feed2imap/cache.rb', line 95 def nbchannels @channels.length end |
#nbitems ⇒ Object
Return the number of items in the cache
100 101 102 103 104 105 106 |
# File 'lib/feed2imap/cache.rb', line 100 def nbitems nb = 0 @channels.each_value { |c| nb += c.nbitems } nb end |
#parse_failed(id) ⇒ Object
Parsing failure. returns number of failures
75 76 77 |
# File 'lib/feed2imap/cache.rb', line 75 def parse_failed(id) @channels[id].parse_failed end |
#save(io) ⇒ Object
Save the cache to an IO stream
90 91 92 |
# File 'lib/feed2imap/cache.rb', line 90 def save(io) Marshal.dump([@@cacheidx, @channels], io) end |
#set_last_check(id, time) ⇒ Object
Get the last time the cache was updated
60 61 62 63 64 65 |
# File 'lib/feed2imap/cache.rb', line 60 def set_last_check(id, time) @channels[id] ||= CachedChannel::new @channels[id].lastcheck = time @channels[id].failures = 0 self end |