changed: the way of building the cmslu
main Makefile is in an application directory in cmslu/ there are only libraries: core.a content.a confparser.a templates.a added: macros APPTEMPLATES APPFUNCTIONS defined in the application's Makefile added: PatternCacher added: cmslu function 'run' files which have exec permissions can be run (run is a default function) after read from the database the content is parsed into Ezc::Pattern object, this object is then cached in PatternCacher added: FunctionCodeParser - will be used to parse the code from standard functions (ls/cat/...) git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@475 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
136
templates/patterncacher.cpp
Executable file
136
templates/patterncacher.cpp
Executable file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "patterncacher.h"
|
||||
|
||||
|
||||
PatternCacher::PatternCacher()
|
||||
{
|
||||
// !! tymczasowe wartosci dla testow
|
||||
when_delete_patterns = 3; // 130
|
||||
how_many_delete = 2; // 30
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::CheckTableSize()
|
||||
{
|
||||
if( pattern_tab.size() < when_delete_patterns )
|
||||
return;
|
||||
|
||||
PatternTab::iterator i;
|
||||
PatternErase pe;
|
||||
size_t erase_index;
|
||||
|
||||
erase_tab.resize(pattern_tab.size());
|
||||
|
||||
for( i=pattern_tab.begin(), erase_index=0 ; i!=pattern_tab.end() ; ++i, ++erase_index)
|
||||
{
|
||||
pe.used = i->second.used;
|
||||
pe.iter = i;
|
||||
|
||||
erase_tab[erase_index] = pe;
|
||||
}
|
||||
|
||||
// sorting through 'used'
|
||||
std::sort(erase_tab.begin(), erase_tab.end());
|
||||
|
||||
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;
|
||||
|
||||
pattern_tab.erase(erase_tab[erase_index].iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::CreatePattern(const Item & item, Ezc::Pattern & pattern)
|
||||
{
|
||||
pattern.allow_include = false;
|
||||
pattern.ParseString(item.content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
|
||||
{
|
||||
CheckTableSize();
|
||||
|
||||
PatternUsed pu;
|
||||
|
||||
CreatePattern(item, pu.pattern);
|
||||
pu.used = 1;
|
||||
pu.item_id = item.id;
|
||||
|
||||
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;
|
||||
|
||||
return &(res.first->second.pattern);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * PatternCacher::GetPattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
return AddPattern(item);
|
||||
else
|
||||
{
|
||||
log << log2 << "PC: taking a pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
|
||||
++(i->second.used);
|
||||
return &(i->second.pattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::UpdatePattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
{
|
||||
log << log2 << "PC: there is no such an item to update, id: " << item.id << ", url: " << item.url << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
++(i->second.used);
|
||||
CreatePattern(item, i->second.pattern);
|
||||
|
||||
log << log2 << "PC: updated pattern, id: " << item.id << ", url: " << item.url << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::DeletePattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
{
|
||||
log << log2 << "PC: there is no such an item to delete, id: " << item.id << ", url: " << item.url << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
log << log2 << "PC: deleted pattern, id: " << item.id << ", url: " << item.url << logend;
|
||||
|
||||
pattern_tab.erase(i);
|
||||
}
|
Reference in New Issue
Block a user