summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cache.rb')
-rw-r--r--lib/cache.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/cache.rb b/lib/cache.rb
index c2968d1..f635114 100644
--- a/lib/cache.rb
+++ b/lib/cache.rb
@@ -32,4 +32,38 @@ class MessageCountCache
update!
end
end
+end
+
+class MostRecentMessagesCache
+ include Singleton
+ CACHE_SECONDS=3600
+
+ def initialize
+ update!
+ end
+
+ def update!
+ @messages ||= {}
+
+ @new_messages = {}
+ [$config['active_lists'], $config['frozen_lists']].flatten.each do |list|
+ @new_messages[list] = most_recent(list, 5)
+ end
+
+ @messages = @new_messages
+ @load_date = DateTime.now
+ end
+
+ def [](list)
+ update?
+
+ @messages[list] || []
+ end
+
+ private
+ def update?
+ if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
+ update!
+ end
+ end
end \ No newline at end of file