You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2017/09/06 15:08:43 UTC

[whimsy] 01/02: stronger caching

This is an automated email from the ASF dual-hosted git repository.

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

commit f4185d0914828c7ba0ead327d95a7bbf24a21181
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Wed Sep 6 11:08:01 2017 -0400

    stronger caching
---
 www/roster/main.rb | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/www/roster/main.rb b/www/roster/main.rb
index 8925dae..5786bf6 100755
--- a/www/roster/main.rb
+++ b/www/roster/main.rb
@@ -54,27 +54,35 @@ get '/committee' do
   redirect to('/committee/')
 end
 
-@index = nil
-@index_time = nil
+@@index = nil
+@@index_time = nil
+@@index_etag = nil
 get '/committer/index.json' do
-  @index = nil unless @index_time and Time.now-@index_tine < 300
+  @@index = nil if not @@index_time or Time.now-@@index_time > 300
 
-  if not @index
+  if not @@index
     # bulk loading the mail information makes things go faster
     mail = Hash[ASF::Mail.list.group_by(&:last).
       map {|person, list| [person, list.map(&:first)]}]
 
-    # return a list of people, their public-names, and email addresses
-    @index = ASF::Person.list.sort_by(&:id).map {|person|
+    # build a list of people, their public-names, and email addresses
+    @@index = ASF::Person.list.sort_by(&:id).map {|person|
       result = {id: person.id, name: person.public_name, mail: mail[person]}
       result[:member] = true if person.asf_member?
       result
-    }
-  end
+    }.to_json
 
-  _json do
-    @index
+    # cache
+    @@index_time = Time.now
+    @@index_etag = etag = Digest::MD5.hexdigest(@@index)
   end
+
+  # send response
+  last_modified @@index_time
+  etag @@index_etag
+  headers 'type' => 'application/json', 'charset' => 'UTF-8'
+  expires [Time.now-@@index_time, 60].max
+  @@index
 end
 
 get '/committee/:name.json' do |name|

-- 
To stop receiving notification emails like this one, please contact
"commits@whimsical.apache.org" <co...@whimsical.apache.org>.