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

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:

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.

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:
http://labs.frickle.com/nginx_ngx_cache_purge/

Best regards,
Piotr S. < [email protected] >

Great link, thanks

Posted at Nginx Forum: