2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Remove expired cookies first when cookies_ is full.
	* src/CookieStorage.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-10-10 09:22:04 +00:00
parent 0abd4a2f7b
commit bcddb4cfa3
2 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Remove expired cookies first when cookies_ is full.
* src/CookieStorage.cc
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten util::split()

View File

@ -70,13 +70,21 @@ bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
return false;
} else {
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
// TODO First remove expired cookie
cookies_.erase
(std::remove_if(cookies_.begin(), cookies_.end(),
std::bind2nd
(std::mem_fun_ref(&Cookie::isExpired), now)),
cookies_.end());
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
std::deque<Cookie>::iterator m = std::min_element
(cookies_.begin(), cookies_.end(), LeastRecentAccess<Cookie>());
*m = cookie;
} else {
cookies_.push_back(cookie);
}
} else {
cookies_.push_back(cookie);
}
return true;
}
} else if(cookie.isExpired(now)) {
@ -113,8 +121,6 @@ static const double DOMAIN_EVICTION_RATE = 0.1;
bool CookieStorage::store(const Cookie& cookie, time_t now)
{
if(domains_.size() >= DOMAIN_EVICTION_TRIGGER) {
// TODO Do this in a separete Command.
// TODO Erase expired cookie first
std::sort(domains_.begin(), domains_.end(),
LeastRecentAccess<DomainEntry>());
size_t delnum = (size_t)(domains_.size()*DOMAIN_EVICTION_RATE);