Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Maintain Apache cache folder |
|
Author |
|
GadiK
Joined: 14 Jul 2010 Posts: 14
|
Posted: Wed 14 Jul '10 13:37 Post subject: Maintain Apache cache folder |
|
|
Hello.
I'm working with Apache server (Windows 2k3 server) and I want control the size of its cache folder.
I am aware of the htcacheclean tool but I am trying to configure Apache to maintain its cache folder so that I won't have to use said tool.
I've entered the following directives into httpd.exe:
Code: |
LoadModule cache_module modules/mod_cache.so
LoadModule disk_cache_module modules/mod_disk_cache.so
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot "C:\Program Files\Apache22\cache"
CacheEnable disk /subdir/file
CacheDirLevels 3
CacheDirLength 3
CacheDefaultExpire 3600
CacheMaxFileSize 200000000
</IfModule>
</IfModule>
|
With this configuration I expect the cache folder to have only file that are younger than 1 hour.
However, this is not the case. Files that were created in the cache folder days ago are still there.
How can I configure Apache to erase files that are over a certain age? (not using htcacheclean)
Thank you. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 14 Jul '10 16:03 Post subject: |
|
|
AFAIK there is only the choise of using htcacheclean. |
|
Back to top |
|
GadiK
Joined: 14 Jul 2010 Posts: 14
|
Posted: Wed 14 Jul '10 16:27 Post subject: |
|
|
Thank you for replying.
I don't understand what the directive CacheDefaultExpire stands for?
Shouldn't it set the expiration time and enforce mod_disk_cache to erase all expired files?
Thanks. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
GadiK
Joined: 14 Jul 2010 Posts: 14
|
Posted: Thu 15 Jul '10 9:06 Post subject: |
|
|
Thank you for your suggestion. However, I am expecting large files in my cache, thus, I avoid using the mem_cache option.
I find what you said about mod_disk_cache not deleting expired files most interesting, since I understood the complete opposite from the documentation.
http://httpd.apache.org/docs/2.2/caching.html#disk
Under "Maintaining the Disk Cache" section, the first paragraph states:
Quote: | Although mod_disk_cache will remove cached content as it is expired, it does not maintain any information on the total size of the cache or how little free space may be left. |
So mod_disk_cache doesn't limit the cache directory size, but does it erase expired files?
Thank you.
Last edited by GadiK on Thu 15 Jul '10 10:20; edited 1 time in total |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
|
Back to top |
|
GadiK
Joined: 14 Jul 2010 Posts: 14
|
Posted: Thu 15 Jul '10 10:18 Post subject: |
|
|
glsmith, could you please elaborate?
I've read the document and I found no statement that says something about erasing files.
There is, however, a function in mod_disk_cache.c which seems to erase expired files:
Code: |
static int remove_url(cache_handle_t *h, apr_pool_t *p)
{
apr_status_t rc;
disk_cache_object_t *dobj;
/* Get disk cache object from cache handle */
dobj = (disk_cache_object_t *) h->cache_obj->vobj;
if (!dobj) {
return DECLINED;
}
/* Delete headers file */
if (dobj->hdrsfile) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
"disk_cache: Deleting %s from cache.", dobj->hdrsfile);
rc = apr_file_remove(dobj->hdrsfile, p);
if ((rc != APR_SUCCESS) && !APR_STATUS_IS_ENOENT(rc)) {
/* Will only result in an output if httpd is started with -e debug.
* For reason see log_error_core for the case s == NULL.
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, NULL,
"disk_cache: Failed to delete headers file %s from cache.",
dobj->hdrsfile);
return DECLINED;
}
}
/* Delete data file */
if (dobj->datafile) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
"disk_cache: Deleting %s from cache.", dobj->datafile);
rc = apr_file_remove(dobj->datafile, p);
if ((rc != APR_SUCCESS) && !APR_STATUS_IS_ENOENT(rc)) {
/* Will only result in an output if httpd is started with -e debug.
* For reason see log_error_core for the case s == NULL.
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, NULL,
"disk_cache: Failed to delete data file %s from cache.",
dobj->datafile);
return DECLINED;
}
}
/* now delete directories as far as possible up to our cache root */
if (dobj->root) {
const char *str_to_copy;
str_to_copy = dobj->hdrsfile ? dobj->hdrsfile : dobj->datafile;
if (str_to_copy) {
char *dir, *slash, *q;
dir = apr_pstrdup(p, str_to_copy);
/* remove filename */
slash = strrchr(dir, '/');
*slash = '\0';
/*
* now walk our way back to the cache root, delete everything
* in the way as far as possible
*
* Note: due to the way we constructed the file names in
* header_file and data_file, we are guaranteed that the
* cache_root is suffixed by at least one '/' which will be
* turned into a terminating null by this loop. Therefore,
* we won't either delete or go above our cache root.
*/
for (q = dir + dobj->root_len; *q ; ) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
"disk_cache: Deleting directory %s from cache",
dir);
rc = apr_dir_remove(dir, p);
if (rc != APR_SUCCESS && !APR_STATUS_IS_ENOENT(rc)) {
break;
}
slash = strrchr(q, '/');
*slash = '\0';
}
}
}
return OK;
}
|
It leads me to believe there is a configurable way to erase expired files. |
|
Back to top |
|
|
|
|
|
|