whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: WHIMSY-278 - re-instate cache, but validate it
Date Sat, 20 Jul 2019 23:43:55 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 67e347e  WHIMSY-278 - re-instate cache, but validate it
67e347e is described below

commit 67e347ea92e830bb174f31b385fca516bc3070be
Author: Sebb <sebb@apache.org>
AuthorDate: Sun Jul 21 00:43:51 2019 +0100

    WHIMSY-278 - re-instate cache, but validate it
---
 lib/whimsy/asf/member.rb | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/whimsy/asf/member.rb b/lib/whimsy/asf/member.rb
index 677bca2..c1b947f 100644
--- a/lib/whimsy/asf/member.rb
+++ b/lib/whimsy/asf/member.rb
@@ -6,7 +6,11 @@ module ASF
     @@text = nil
     @@mtime = 0
 
-    # Return the members.txt value assocaited with a given id
+    def self.mtime
+      @@mtime
+    end
+
+    # Return the members.txt value associated with a given id
     def self.find_text_by_id(value)
       new.each do |id, text|
         return text if id==value
@@ -175,8 +179,13 @@ module ASF
     # this will also include the text delimiters.
     def members_txt(full = false)
       prefix, suffix = " *) ", "\n\n" if full
-      # TODO work out how to cache this safely (WHIMSY-278)
-      @members_txt = ASF::Member.find_text_by_id(id)
+      # Is the cached text still valid?
+      unless @members_time == ASF::Member.mtime
+        @members_txt = nil
+      end
+      # cache the text and its time (may be changed by the find operation)
+      @members_txt ||= ASF::Member.find_text_by_id(id)
+      @members_time = ASF::Member.mtime
       "#{prefix}#{@members_txt}#{suffix}" if @members_txt
     end
 


Mime
View raw message