Max catalog age configurable per-catalog.

Allows for short-validity catalogs for development use.
This commit is contained in:
James Turner
2013-03-03 23:03:09 +00:00
parent ceae2928aa
commit fe9caad391
4 changed files with 22 additions and 4 deletions

View File

@@ -290,6 +290,12 @@ unsigned int Catalog::ageInSeconds() const
return (diff < 0) ? 0 : diff;
}
bool Catalog::needsRefresh() const
{
unsigned int maxAge = m_props->getIntValue("max-age-sec", m_root->maxAgeSeconds());
return (ageInSeconds() > maxAge);
}
std::string Catalog::getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const
{
if (aRoot->hasChild(m_root->getLocale())) {

View File

@@ -83,6 +83,12 @@ public:
Package* getPackageById(const std::string& aId) const;
/**
* test if the catalog data was retrieved longer ago than the
* maximum permitted age for this catalog.
*/
bool needsRefresh() const;
unsigned int ageInSeconds() const;
/**

View File

@@ -68,10 +68,15 @@ SGPath Root::path() const
return d->path;
}
void Root::setMaxAgeSeconds(int seconds)
void Root::setMaxAgeSeconds(unsigned int seconds)
{
d->maxAgeSeconds = seconds;
}
unsigned int Root::maxAgeSeconds() const
{
return d->maxAgeSeconds;
}
void Root::setHTTPClient(HTTP::Client* aHTTP)
{
@@ -207,7 +212,7 @@ void Root::refresh(bool aForce)
{
CatalogDict::iterator it = d->catalogs.begin();
for (; it != d->catalogs.end(); ++it) {
if (aForce || (it->second->ageInSeconds() > d->maxAgeSeconds)) {
if (aForce || it->second->needsRefresh()) {
it->second->refresh();
}
}

View File

@@ -61,8 +61,9 @@ public:
CatalogList catalogs() const;
void setMaxAgeSeconds(int seconds);
void setMaxAgeSeconds(unsigned int seconds);
unsigned int maxAgeSeconds() const;
void setHTTPClient(HTTP::Client* aHTTP);
/**