/*
- * $Id: cache_cf.cc,v 1.82 1996/09/04 23:42:01 wessels Exp $
+ * $Id: cache_cf.cc,v 1.83 1996/09/05 19:02:51 wessels Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
#define DefaultWaisRelayHost (char *)NULL
#define DefaultWaisRelayPort 0
+#define DefaultExpireAge (86400 * 7) /* 1 week */
#define DefaultNegativeTtl (5 * 60) /* 5 min */
#define DefaultNegativeDnsTtl (2 * 60) /* 2 min */
#define DefaultPositiveDnsTtl (360 * 60) /* 6 hours */
static void parseAppendDomainLine _PARAMS((void));
static void parseCacheAnnounceLine _PARAMS((void));
static void parseCacheHostLine _PARAMS((void));
-static void parseCleanRateLine _PARAMS((void));
static void parseDebugOptionsLine _PARAMS((void));
static void parseDirLine _PARAMS((void));
static void parseDnsProgramLine _PARAMS((void));
static void parseIPLine _PARAMS((ip_acl ** list));
static void parseIcpPortLine _PARAMS((void));
static void parseInsideFirewallLine _PARAMS((void));
-static void parseLifetimeLine _PARAMS((void));
static void parseLocalDomainFile _PARAMS((char *fname));
static void parseLocalDomainLine _PARAMS((void));
static void parseLogLine _PARAMS((void));
static void parseMemLine _PARAMS((void));
static void parseMgrLine _PARAMS((void));
-static void parseNegativeDnsLine _PARAMS((void));
-static void parseNegativeLine _PARAMS((void));
static void parsePidFilenameLine _PARAMS((void));
-static void parsePositiveDnsLine _PARAMS((void));
-static void parseReadTimeoutLine _PARAMS((void));
static void parseRequestSizeLine _PARAMS((void));
static void parseStoreLogLine _PARAMS((void));
static void parseSwapLine _PARAMS((void));
static void parseTTLPattern _PARAMS((int icase, int force));
static void parseVisibleHostnameLine _PARAMS((void));
static void parseWAISRelayLine _PARAMS((void));
+static void parseMinutesLine _PARAMS((int *));
void self_destruct()
{
}
}
-static void parseNegativeLine()
-{
- char *token;
- int i;
- GetInteger(i);
- Config.negativeTtl = i * 60;
-}
-
-static void parseNegativeDnsLine()
-{
- char *token;
- int i;
- GetInteger(i);
- Config.negativeDnsTtl = i * 60;
-}
-
-static void parsePositiveDnsLine()
-{
- char *token;
- int i;
- GetInteger(i);
- Config.positiveDnsTtl = i * 60;
-}
-
-static void parseReadTimeoutLine()
-{
- char *token;
- int i;
- GetInteger(i);
- Config.readTimeout = i * 60;
-}
-
-static void parseLifetimeLine()
-{
- char *token;
- int i;
- GetInteger(i);
- Config.lifetimeDefault = i * 60;
-}
-
-static void parseCleanRateLine()
+static void parseMinutesLine(iptr)
+ int *iptr;
{
char *token;
int i;
GetInteger(i);
- Config.cleanRate = i * 60;
+ *iptr = i * 60;
}
static void parseRequestSizeLine()
parseQuickAbort();
else if (!strcmp(token, "negative_ttl"))
- parseNegativeLine();
-
+ parseMinutesLine(&Config.negativeTtl);
else if (!strcmp(token, "negative_dns_ttl"))
- parseNegativeDnsLine();
-
+ parseMinutesLine(&Config.negativeDnsTtl);
else if (!strcmp(token, "positive_dns_ttl"))
- parsePositiveDnsLine();
-
+ parseMinutesLine(&Config.positiveDnsTtl);
else if (!strcmp(token, "read_timeout"))
- parseReadTimeoutLine();
-
+ parseMinutesLine(&Config.readTimeout);
else if (!strcmp(token, "clean_rate"))
- parseCleanRateLine();
-
+ parseMinutesLine(&Config.cleanRate);
else if (!strcmp(token, "client_lifetime"))
- parseLifetimeLine();
+ parseMinutesLine(&Config.lifetimeDefault);
+ else if (!strcmp(token, "expire_age"))
+ parseMinutesLine(&Config.expireAge);
else if (!strcmp(token, "shutdown_lifetime"))
parseIntegerValue(&Config.lifetimeShutdown);
Config.Wais.relayHost = safe_xstrdup(DefaultWaisRelayHost);
Config.Wais.relayPort = DefaultWaisRelayPort;
+ Config.expireAge = DefaultExpireAge;
Config.negativeTtl = DefaultNegativeTtl;
Config.negativeDnsTtl = DefaultNegativeDnsTtl;
Config.positiveDnsTtl = DefaultPositiveDnsTtl;
/*
- * $Id: ftp.cc,v 1.52 1996/09/03 19:24:02 wessels Exp $
+ * $Id: ftp.cc,v 1.53 1996/09/05 19:02:55 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
break;
default:
/* These can be negative cached, make key public */
- entry->expires = squid_curtime + Config.negativeTtl;
+ storeNegativeCache(entry);
if (BIT_TEST(entry->flag, ENTRY_CACHABLE))
storeSetPublicKey(entry);
break;
* failed and arrange so the object gets ejected and
* never gets to disk. */
debug(9, 1, "ftpReadReply: Purging '%s'\n", entry->url);
- entry->expires = squid_curtime + Config.negativeTtl;
+ storeNegativeCache(entry);
BIT_RESET(entry->flag, ENTRY_CACHABLE);
storeReleaseRequest(entry);
} else if (!(entry->flag & DELETE_BEHIND)) {
/*
- * $Id: http.cc,v 1.71 1996/09/04 22:03:23 wessels Exp $
+ * $Id: http.cc,v 1.72 1996/09/05 19:02:56 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
static void httpCacheNegatively(entry)
StoreEntry *entry;
{
- entry->expires = squid_curtime + Config.negativeTtl;
+ storeNegativeCache(entry);
if (BIT_TEST(entry->flag, ENTRY_CACHABLE))
storeSetPublicKey(entry);
- /* XXX: mark object "not to store on disk"? */
}
/*
- * $Id: store.cc,v 1.97 1996/09/04 23:42:02 wessels Exp $
+ * $Id: store.cc,v 1.98 1996/09/05 19:02:59 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
if (store_rebuilding != STORE_REBUILDING_FAST) {
if (stat(swapfile, &sb) < 0) {
- if (expires < squid_curtime) {
+ if (squid_curtime - expires > Config.expireAge) {
debug(20, 3, "storeRebuildFromDisk: Expired: <URL:%s>\n", url);
if (opt_unlink_on_reload)
safeunlink(swapfile, 1);
data->objcount--;
data->dupcount++;
}
- if (expires < squid_curtime) {
+ if (squid_curtime - expires > Config.expireAge) {
debug(20, 3, "storeRebuildFromDisk: Expired: <URL:%s>\n", url);
if (opt_unlink_on_reload)
safeunlink(swapfile, 1);
StoreEntry *e;
{
- if (e->expires <= squid_curtime) {
+ if (squid_curtime - e->expires > Config.expireAge) {
debug(20, 2, "storeCheckSwapable: NO: expires now\n");
} else if (e->method != METHOD_GET) {
debug(20, 2, "storeCheckSwapable: NO: non-GET method\n");
debug(20, 2, "storeCheckSwapable: NO: release requested\n");
} else if (!storeEntryValidLength(e)) {
debug(20, 2, "storeCheckSwapable: NO: wrong content-length\n");
- } else if (e->expires <= squid_curtime + Config.negativeTtl) {
- debug(20, 2, "storeCheckSwapable: NO: expires soon\n");
+ } else if (BIT_TEST(e->flag, ENTRY_NEGCACHED)) {
+ debug(20, 2, "storeCheckSwapable: NO: negative cached\n");
return 0; /* avoid release call below */
} else
return 1;
fatal_dump("storeAbort: null mem");
debug(20, 6, "storeAbort: '%s'\n", e->key);
- e->expires = squid_curtime + Config.negativeTtl;
+ storeNegativeCache(e);
e->store_status = STORE_ABORTED;
storeSetMemStatus(e, IN_MEMORY);
/* No DISK swap for negative cached object */
/* remove expired objects until recover enough space or no expired objects */
for (i = 0; i < STORE_BUCKETS; i++) {
int expired_in_one_bucket = 0;
-
link_ptr = hash_get_bucket(store_table, storeGetBucketNum());
if (link_ptr == NULL)
continue;
/* this while loop handles one bucket of hash table */
expired_in_one_bucket = 0;
- while (link_ptr) {
+ for (; link_ptr; link_ptr = next) {
scanned++;
next = link_ptr->next;
e = (StoreEntry *) link_ptr;
-
- /* Identify objects that aren't locked, for replacement */
- if (!storeEntryLocked(e)) {
- if (squid_curtime > e->expires) {
- debug(20, 2, "storeGetSwapSpace: Expired: <URL:%s>\n", e->url);
- /* just call release. don't have to check for lock status.
- * storeRelease will take care of that and set a pending flag
- * if it's still locked. */
- ++expired_in_one_bucket;
- storeRelease(e);
- } else {
- /* Prepare to do LRU replacement */
- insert_dynamic_array(LRU_list, e);
- ++scan_in_objs;
- }
+ if (storeCheckExpired(e)) {
+ debug(20, 2, "storeGetSwapSpace: Expired: <URL:%s>\n", e->url);
+ ++expired_in_one_bucket;
+ storeRelease(e);
+ } else if (!storeEntryLocked(e)) {
+ insert_dynamic_array(LRU_list, e);
+ ++scan_in_objs;
} else {
- locked++;
- locked_size += e->mem_obj->e_current_len;
+ locked++;
+ locked_size += e->mem_obj->e_current_len;
}
- link_ptr = next;
} /* while, end of one bucket of hash table */
-
expired += expired_in_one_bucket;
if (expired_in_one_bucket &&
((!fReduceSwap && (store_swap_size + kb_size <= store_swap_high)) ||
if (store_rebuilding == STORE_REBUILDING_FAST)
return -1;
- /* Scan row of hash table each second and free storage if we're
- * over the high-water mark */
- storeGetSwapSpace(0);
-
/* Purges expired objects, check one bucket on each calling */
if (squid_curtime - last_time >= STORE_MAINTAIN_RATE) {
last_time = squid_curtime;
if (bucket >= STORE_BUCKETS)
bucket = 0;
link_ptr = hash_get_bucket(store_table, bucket++);
- while (link_ptr) {
+ for (;link_ptr; link_ptr = next) {
next = link_ptr->next;
e = (StoreEntry *) link_ptr;
- if ((squid_curtime > e->expires) &&
- (e->swap_status == SWAP_OK)) {
- debug(20, 2, "storeMaintainSwapSpace: Expired: <TTL:%d> <URL:%s>\n",
- e->expires - squid_curtime, e->url);
- /* just call release. don't have to check for lock status.
- * storeRelease will take care of that and set a pending flag
- * if it's still locked. */
- storeRelease(e);
- ++rm_obj;
- }
- link_ptr = next;
+ if (!storeCheckExpired(e))
+ continue;
+ storeRelease(e);
+ ++rm_obj;
}
}
debug(20, rm_obj ? 2 : 3, "Removed %d expired objects\n", rm_obj);
+
+ /* Scan row of hash table each second and free storage if we're
+ * over the high-water mark */
+ storeGetSwapSpace(0);
+
return rm_obj;
}
{
if (storeEntryLocked(e))
return 0;
- if (squid_curtime < e->expires)
+ if (squid_curtime - e->expires < Config.expireAge)
return 0;
return 1;
}
file_close(swaplog_fd);
file_close(storelog_fd);
}
+
+void storeNegativeCache(e)
+ StoreEntry *e;
+{
+ e->expires = squid_curtime + Config.negativeTtl;
+ BIT_SET(e->flag, ENTRY_NEGCACHED);
+}