From bebbc91fb938df116d2168438e14381bd5133442 Mon Sep 17 00:00:00 2001 From: kitaj Date: Sat, 25 Oct 2003 04:46:39 +0000 Subject: [PATCH] * tdiary.rb: auto invalidation of parser cache and ERb cache. git-svn-id: https://tdiary.svn.sourceforge.net/svnroot/tdiary/trunk/core@1641 7f22e88f-374d-0410-998f-c91420d97ba2 --- ChangeLog | 3 +++ tdiary.rb | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7032914dc..cbeaf5530 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2003.10.25 Junichiro Kita + * tdiary.rb: auto invalidation of parser cache and ERb cache. + 2003-10-23 Kazuhiko * plugin/ja/00default.rb, plugin/ja/00default.rb, skel/category.rhtml, skel/conf.rhtml, skel/i.conf.rhtml, diff --git a/tdiary.rb b/tdiary.rb index 0f75bf6b8..7f1d722c3 100644 --- a/tdiary.rb +++ b/tdiary.rb @@ -1,13 +1,13 @@ =begin == NAME tDiary: the "tsukkomi-able" web diary system. -tdiary.rb $Revision: 1.150 $ +tdiary.rb $Revision: 1.151 $ Copyright (C) 2001-2003, TADA Tadashi You can redistribute it and/or modify it under GPL2. =end -TDIARY_VERSION = '1.5.5.20031010' +TDIARY_VERSION = '1.5.5.20031025' require 'cgi' begin @@ -840,8 +840,9 @@ def do_eval_rhtml( prefix ) # load and apply rhtmls if cache_enable?( prefix ) then - r = File::open( "#{cache_path}/#{cache_file( prefix )}" ) {|f| f.read } - else + r = File::open( "#{cache_path}/#{cache_file( prefix )}" ) {|f| f.read } rescue nil + end + if r.nil? files = ["header.rhtml", @rhtml, "footer.rhtml"] rhtml = files.collect {|file| path = "#{PATH}/skel/#{prefix}#{file}" @@ -907,10 +908,14 @@ def cache_enable?( prefix ) def store_cache( cache, prefix ) unless FileTest::directory?( cache_path ) then - Dir::mkdir( cache_path ) + begin + Dir::mkdir( cache_path ) + rescue Errno::EEXIST + end end if cache_file( prefix ) then File::open( "#{cache_path}/#{cache_file( prefix )}", 'w' ) do |f| + f.flock(File::LOCK_EX) f.write( cache ) end end @@ -927,7 +932,10 @@ def parser_cache( date, key = nil, obj = nil ) require 'pstore' unless FileTest::directory?( cache_path ) then - Dir::mkdir( cache_path ) + begin + Dir::mkdir( cache_path ) + rescue Errno::EEXIST + end end file = date.strftime( "#{cache_path}/%Y%m.parser" ) @@ -941,10 +949,16 @@ def parser_cache( date, key = nil, obj = nil ) PStore::new( file ).transaction do |cache| begin unless obj then # restore - obj = cache[key] + ver = cache.root?('version') ? cache['version'] : nil + if ver == TDIARY_VERSION and cache.root?(key) + obj = cache[key] + else + clear_cache + end cache.abort else # store cache[key] = obj + cache['version'] = TDIARY_VERSION end rescue PStore::Error end