logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Maintain Apache cache folder
Author
GadiK



Joined: 14 Jul 2010
Posts: 14

PostPosted: Wed 14 Jul '10 13:37    Post subject: Maintain Apache cache folder Reply with quote

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

PostPosted: Wed 14 Jul '10 16:03    Post subject: Reply with quote

AFAIK there is only the choise of using htcacheclean.
Back to top
GadiK



Joined: 14 Jul 2010
Posts: 14

PostPosted: Wed 14 Jul '10 16:27    Post subject: Reply with quote

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

PostPosted: Wed 14 Jul '10 22:45    Post subject: Reply with quote

I think that apache will look for a "new version" after that time which is set in CacheDefaultExpire the cached files won't deleted. mod_disk_cache doesn't care about the usage on the disk.

Maybe the caching guide[1] helps you to understand how mod_disk_cache works.


For more performance you can use mod_mem_cache[2] it also offers two CacheRemovalAlgorithms[3] to reduce the files in the cache. Maybe that is more your favor.


[1] http://httpd.apache.org/docs/2.2/de/caching.html#disk
[2] http://httpd.apache.org/docs/2.2/de/mod/mod_mem_cache.html
[3] http://httpd.apache.org/docs/2.2/de/mod/mod_mem_cache.html#mcacheremovalalgorithm
Back to top
GadiK



Joined: 14 Jul 2010
Posts: 14

PostPosted: Thu 15 Jul '10 9:06    Post subject: Reply with quote

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

PostPosted: Thu 15 Jul '10 9:32    Post subject: Reply with quote

It seems to infer that, but there seems to be more to it in the bigger picture.

http://httpd.apache.org/docs/2.2/mod/mod_cache.html
Back to top
GadiK



Joined: 14 Jul 2010
Posts: 14

PostPosted: Thu 15 Jul '10 10:18    Post subject: Reply with quote

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


Reply to topic   Topic: Maintain Apache cache folder View previous topic :: View next topic
Post new topic   Forum Index -> Apache