# Purge files from proxy\_cache

**URL:** <https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837>\
**Category:** NGINX\
**Created:** [April 13, 2012, 9:38am UTC](https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837 "2012-04-13T09:38:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 13, 2012, 9:38am UTC](https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837/1 "2012-04-13T09:38:28Z")

</div>

Hi, i’ve set a proxy cache for my app ( app is allso served by nginx ).  
My problem is that i would like to have my app control the cache a  
little bit so i have hooks that delete files whith keys matching certain  
paths when some events in the app take place. This also works ok but the  
problem is that during stress testing if i remove a file from the nginx  
cache i get a lot of php-fpm processes stampeeding to generate that file  
in the cache.

I would like to mention that i am using proxy\_cache\_use\_stale updating  
in order to prevent stampeeding when nginx needs to rebuild cached pages  
that have expired naturally but that won’t help when i remove them from  
the cache myself.

Question is … how can i make certain pages expire when the application  
decides they need to be refreshed ? or … how can i safely delete them  
and not have a php riot ?

Posted at Nginx Forum:

> **[Purge files from proxy\_cache](https://forum.nginx.org/read.php?2,225281,225281#msg-225281)**
>
> Hi, i've set a proxy cache for my app ( app is allso served by nginx ). My problem is that i would like to have my app control the cache a little bit so i have hooks that delete files whith keys matching certain paths when some events in the app take...

---

<div class="post-metadata">

**Author:** ![mlmarius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@mlmarius](https://www.ruby-forum.com/u/mlmarius)\
**Post date:** [April 13, 2012, 9:43am UTC](https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837/2 "2012-04-13T09:43:26Z")

</div>

> that have expired naturally but that won’t help when i remove them from  
> the cache myself.
> 
> Question is … how can i make certain pages expire when the application  
> decides they need to be refreshed ? or … how can i safely delete them  
> and not have a php riot ?

Either use this: [GitHub - FRiCKLE/ngx\_cache\_purge: nginx module which adds ability to purge content from FastCGI, proxy, SCGI and uWSGI caches. · GitHub](https://github.com/FRiCKLE/ngx_cache_purge)

Or just delete the file. This could be handy in that case:

> **[GitHub - perusio/nginx-cache-purge: A bash script for deleting items from Nginx cache](https://github.com/perusio/nginx-cache-purge)**
>
> A bash script for deleting items from Nginx cache

–appa

---

<div class="post-metadata">

**Author:** ![mlmarius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@mlmarius](https://www.ruby-forum.com/u/mlmarius)\
**Post date:** [April 13, 2012, 10:08am UTC](https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837/3 "2012-04-13T10:08:56Z")

</div>

## Antonio P.P. Almeida Wrote:

> > cache i get a lot of php-fpm processes
> 
> that case:
> 
> [GitHub - perusio/nginx-cache-purge: A bash script for deleting items from Nginx cache · GitHub](https://github.com/perusio/nginx-cache-purge)
> 
> –appa
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Well … i kind of figured out how to actually delete the files from the  
cache by greping for certain key patterns so i am able to actually  
remove them. The problem is that right after i remove them nginx will  
try to rebuild them and at 1000 req/s a lot of php-php processes will  
come up to try and generate the missing cache page which will cause a  
drop in the reqs’s ( i think requests start getting http error pages  
actually ). So that is my problem … the fact that i have no control  
over how uncached pages are created. I would like just 1 process to  
generate the missing page and the others to wait for it to be available  
or something. I guess i’m looging for the functionality that

proxy\_cache\_use\_stale updating

adds but for missing files. That will only keep me safe from updating of  
cached and expired pages.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,225281,225285#msg-225285](http://forum.nginx.org/read.php?2,225281,225285#msg-225285)

---

<div class="post-metadata">

**Author:** ![mlmarius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@mlmarius](https://www.ruby-forum.com/u/mlmarius)\
**Post date:** [April 13, 2012, 10:17am UTC](https://www.ruby-forum.com/t/purge-files-from-proxy-cache/218837/4 "2012-04-13T10:17:38Z")

</div>

> proxy\_cache\_use\_stale updating
> 
> adds but for missing files. That will only keep me safe from updating of  
> cached and expired pages.

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

> **[Module ngx\_http\_fastcgi\_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_lock)**
>
> The ngx\_http\_fastcgi\_module module allows passing requests to a FastCGI server.

–appa
