# What if I just delete a file from cache to invalidate cache item?

**URL:** <https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203>\
**Category:** NGINX\
**Created:** [November 16, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203 "2010-11-16T19:15:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 16, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203/1 "2010-11-16T19:15:51Z")

</div>

I have a system handling tons of requests per second (god bless nginx).  
I have  
proxy\_cache\_key “$request\_uri”;  
proxy\_cache\_valid 200 1s;

I need to increase the cache lifetime.  
What if I set proxy\_cache\_valid to something large, and when my data  
changes (cache dependency),  
I would caclulate md5(request\_uri) and go to  
/my\_nginx\_cache\_dir/a/ab/abc… and just delete the corresponding  
cache item.

Will it work? I mean it will of course. But will it have a potential  
problem when my delete\_the\_file system call can interfere with the nginx  
internal cache read routines?

Thanks

Posted at Nginx Forum:

> **[What if I just delete a file from cache to invalidate cache item?](https://forum.nginx.org/read.php?2,151218,151218#msg-151218)**
>
> I have a system handling tons of requests per second (god bless nginx). I have proxy\_cache\_key "$request\_uri"; proxy\_cache\_valid 200 1s; I need to increase the cache lifetime. What if I set proxy\_cache\_valid to something large, and when my...

---

<div class="post-metadata">

**Author:** ![ttyx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2bfe46/32.png) [@ttyx](https://www.ruby-forum.com/u/ttyx)\
**Post date:** [November 16, 2010, 7:40pm UTC](https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203/2 "2010-11-16T19:40:56Z")

</div>

Hello!

On Tue, Nov 16, 2010 at 01:14:38PM -0500, ttyx wrote:

> cache item.
> 
> Will it work? I mean it will of course.

Yes it will.

> But will it have a potential  
> problem when my delete\_the\_file system call can interfere with the nginx  
> internal cache read routines?

No.

The only potential problem is that nginx wouldn’t be immediatly  
aware of deleted cache files (it will find this out once it’ll try  
to access cache file) and information about total cache disk usage  
may be off from real life (and hence nginx won’t be able to maintain  
correct cache max\_size).

Maxim D.

---

<div class="post-metadata">

**Author:** ![ttyx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2bfe46/32.png) [@ttyx](https://www.ruby-forum.com/u/ttyx)\
**Post date:** [November 17, 2010, 6:25am UTC](https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203/3 "2010-11-17T06:25:00Z")

</div>

Hi,

> I need to increase the cache lifetime.  
> What if I set proxy\_cache\_valid to something large, and when my data  
> changes (cache dependency),  
> I would caclulate md5(request\_uri) and go to  
> /my\_nginx\_cache\_dir/a/ab/abc… and just delete the corresponding  
> cache item.

You should really look into ngx\_cache\_purge module:

> **[FRiCKLE Labs / nginx / ngx\_cache\_purge](http://labs.frickle.com/nginx_ngx_cache_purge/)**

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![ttyx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2bfe46/32.png) [@ttyx](https://www.ruby-forum.com/u/ttyx)\
**Post date:** [November 17, 2010, 9:46am UTC](https://www.ruby-forum.com/t/what-if-i-just-delete-a-file-from-cache-to-invalidate-cache-item/199203/4 "2010-11-17T09:46:19Z")

</div>

Great link, thanks

Posted at Nginx Forum:

> **[Re: What if I just delete a file from cache to invalidate cache item?](https://forum.nginx.org/read.php?2,151218,151344#msg-151344)**
>
> I have a system handling tons of requests per second (god bless nginx). I have proxy\_cache\_key "$request\_uri"; proxy\_cache\_valid 200 1s; I need to increase the cache lifetime. What if I set proxy\_cache\_valid to something large, and when my...
