fixed: as we have insert_page ezc function now

we cannot delete ezc patterns when PatternCacher::GetPattern() method is called
       because we can delete a pattern which is in use
       now deleting is performed at the end of a request


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@751 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-07-15 02:09:02 +00:00
parent 1812a2e9ad
commit c37c1ff812
9 changed files with 108 additions and 54 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -14,10 +14,8 @@
PatternCacher::PatternCacher()
{
// !! tymczasowe wartosci dla testow
when_delete_patterns = 3; // 130
how_many_delete = 2; // 30
when_delete_patterns = 13;
how_many_delete = 3;
ezc_fun = 0;
}
@@ -28,7 +26,15 @@ void PatternCacher::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
}
void PatternCacher::CheckTableSize()
void PatternCacher::SetWhenDelete(size_t when_delete, size_t how_many_del)
{
when_delete_patterns = when_delete;
how_many_delete = how_many_del;
}
void PatternCacher::DeleteOldPatterns()
{
if( pattern_tab.size() < when_delete_patterns )
return;
@@ -52,7 +58,10 @@ void PatternCacher::CheckTableSize()
for(erase_index = 0 ; erase_index<how_many_delete && erase_index<erase_tab.size() ; ++erase_index)
{
log << log2 << "PC: deleting from cache, id: " << erase_tab[erase_index].iter->second.item_id << logend;
log << log2 << "PC: deleting ezc pattern from the cache, id: "
<< erase_tab[erase_index].iter->second.item_id
<< ", item used: " << erase_tab[erase_index].used << " time(s)"
<< logend;
pattern_tab.erase(erase_tab[erase_index].iter);
}
@@ -73,7 +82,9 @@ void PatternCacher::CreatePattern(const Item & item, Ezc::Pattern & pattern)
Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
{
CheckTableSize();
// don't call DeleteOldPatterns() here
// because you can delete a pattern which is in use
// (think about ezc functions: item run, insert_page etc)
PatternUsed pu;
@@ -83,7 +94,7 @@ Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
std::pair<PatternTab::iterator, bool> res = pattern_tab.insert( std::make_pair(item.id, pu) );
log << log2 << "PC: added an item, id: " << item.id << ", url: " << item.url << logend;
log << log2 << "PC: added ezc pattern, item_id: " << item.id << ", url: " << item.url << logend;
return &(res.first->second.pattern);
}
@@ -101,7 +112,7 @@ PatternTab::iterator i;
return AddPattern(item);
else
{
log << log2 << "PC: taking a pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
log << log2 << "PC: taking pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
++(i->second.used);
return &(i->second.pattern);
}
@@ -141,3 +152,11 @@ PatternTab::iterator i;
pattern_tab.erase(i);
}
size_t PatternCacher::Size()
{
return pattern_tab.size();
}