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
+6
View File
@@ -290,6 +290,12 @@ unsigned int Catalog::ageInSeconds() const
return (diff < 0) ? 0 : diff; 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 std::string Catalog::getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const
{ {
if (aRoot->hasChild(m_root->getLocale())) { if (aRoot->hasChild(m_root->getLocale())) {
+6
View File
@@ -83,6 +83,12 @@ public:
Package* getPackageById(const std::string& aId) const; 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; unsigned int ageInSeconds() const;
/** /**
+7 -2
View File
@@ -68,10 +68,15 @@ SGPath Root::path() const
return d->path; return d->path;
} }
void Root::setMaxAgeSeconds(int seconds) void Root::setMaxAgeSeconds(unsigned int seconds)
{ {
d->maxAgeSeconds = seconds; d->maxAgeSeconds = seconds;
} }
unsigned int Root::maxAgeSeconds() const
{
return d->maxAgeSeconds;
}
void Root::setHTTPClient(HTTP::Client* aHTTP) void Root::setHTTPClient(HTTP::Client* aHTTP)
{ {
@@ -207,7 +212,7 @@ void Root::refresh(bool aForce)
{ {
CatalogDict::iterator it = d->catalogs.begin(); CatalogDict::iterator it = d->catalogs.begin();
for (; it != d->catalogs.end(); ++it) { for (; it != d->catalogs.end(); ++it) {
if (aForce || (it->second->ageInSeconds() > d->maxAgeSeconds)) { if (aForce || it->second->needsRefresh()) {
it->second->refresh(); it->second->refresh();
} }
} }
+3 -2
View File
@@ -61,8 +61,9 @@ public:
CatalogList catalogs() const; CatalogList catalogs() const;
void setMaxAgeSeconds(int seconds); void setMaxAgeSeconds(unsigned int seconds);
unsigned int maxAgeSeconds() const;
void setHTTPClient(HTTP::Client* aHTTP); void setHTTPClient(HTTP::Client* aHTTP);
/** /**