Max catalog age configurable per-catalog.
Allows for short-validity catalogs for development use.
This commit is contained in:
@@ -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())) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -68,11 +68,16 @@ 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)
|
||||||
{
|
{
|
||||||
d->http = aHTTP;
|
d->http = 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ 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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user