Skip to content

Commit

Permalink
* tdiary.rb: auto invalidation of parser cache and ERb cache.
Browse files Browse the repository at this point in the history
git-svn-id: https://tdiary.svn.sourceforge.net/svnroot/tdiary/trunk/core@1641 7f22e88f-374d-0410-998f-c91420d97ba2
  • Loading branch information
kitaj committed Oct 25, 2003
1 parent b4155df commit bebbc91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
2003.10.25 Junichiro Kita <kita@kitaj.no-ip.com>
* tdiary.rb: auto invalidation of parser cache and ERb cache.

2003-10-23 Kazuhiko <kazuhiko@fdiary.net>
* plugin/ja/00default.rb, plugin/ja/00default.rb,
skel/category.rhtml, skel/conf.rhtml, skel/i.conf.rhtml,
Expand Down
28 changes: 21 additions & 7 deletions 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 <sho@spc.gr.jp>
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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand All @@ -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" )

Expand All @@ -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
Expand Down

0 comments on commit bebbc91

Please sign in to comment.