# What does open\_file\_cache\_events do?

**URL:** <https://www.ruby-forum.com/t/what-does-open-file-cache-events-do/188462>\
**Category:** NGINX\
**Created:** [May 12, 2010, 12:57pm UTC](https://www.ruby-forum.com/t/what-does-open-file-cache-events-do/188462 "2010-05-12T12:57:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Costello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bb73d2/32.png) [@Costello](https://www.ruby-forum.com/u/Costello)\
**Post date:** [May 12, 2010, 12:57pm UTC](https://www.ruby-forum.com/t/what-does-open-file-cache-events-do/188462/1 "2010-05-12T12:57:58Z")

</div>

Hello,

I’m looking to document directives that are missing from the Wiki.  
I found loads in the source code, especially thanks to Manlio P…

I’ve stumbled upon “open\_file\_cache\_events” declared in  
ngx\_http\_core\_module.c.  
I investigated what this does, here is what I found:

- it’s a on/off directive
- it’s off by default
- its main purpose is from 1 file, ngx\_open\_file\_cache.c

That’s where it’s mostly used:

```auto
/*
 * we ignore any possible event setting error and
 * fallback to usual periodic file retests
 */

static void
ngx_open_file_add_event(ngx_open_file_cache_t *cache,
    ngx_cached_open_file_t *file, ngx_open_file_info_t *of, ngx_log_t 
*log)
{
    ngx_open_file_cache_event_t *fev;

    if (!(ngx_event_flags & NGX_USE_VNODE_EVENT)
        || !of->events
        || file->event
        || of->fd == NGX_INVALID_FILE
        || file->uses < of->min_uses)
    {
        return;
    }
```

basically of-\>events takes the value of open\_file\_cache\_events before  
this function is called.  
When called, if of-\>events is false, the flow returns immediately and  
the function is not processed.  
So it prevents Nginx from “adding an event”, I presume for the specified  
file.

Now I understand what the open file cache does, but I don’t understand  
what exactly what this directive does.  
When the directive is enabled, does Nginx process some kind of  
event-based cache invalidation?  
Eg. Nginx would subscribe to events for this file, when the file is  
deleted, Nginx gets notified with an event, and then updates the cache  
entry?

Thanks a lot in advance for helping me clear it out!

Best regards,  
Costello

Posted at Nginx Forum:

> **[What does open\_file\_cache\_events do?](https://forum.nginx.org/read.php?2,85785,85785#msg-85785)**
>
> Hello, I'm looking to document directives that are missing from the Wiki. I found loads in the source code, especially thanks to Manlio Perillo. I've stumbled upon "open\_file\_cache\_events" declared in ngx\_http\_core\_module.c. I investigated...

---

<div class="post-metadata">

**Author:** ![Costello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bb73d2/32.png) [@Costello](https://www.ruby-forum.com/u/Costello)\
**Post date:** [May 12, 2010, 2:17pm UTC](https://www.ruby-forum.com/t/what-does-open-file-cache-events-do/188462/2 "2010-05-12T14:17:34Z")

</div>

Hello!

On Wed, May 12, 2010 at 06:57:24AM -0400, Costello wrote:

> I’m looking to document directives that are missing from the Wiki.  
> I found loads in the source code, especially thanks to Manlio P..
> 
> I’ve stumbled upon “open\_file\_cache\_events” declared in ngx\_http\_core\_module.c.  
> I investigated what this does, here is what I found:
> 
> - it’s a on/off directive
> - it’s off by default
> - its main purpose is from 1 file, ngx\_open\_file\_cache.c

[…]

> Now I understand what the open file cache does, but I don’t  
> understand what exactly what this directive does.  
> When the directive is enabled, does Nginx process some kind of  
> event-based cache invalidation?  
> Eg. Nginx would subscribe to events for this file, when the file  
> is deleted, Nginx gets notified with an event, and then updates  
> the cache entry?

Yes, it activates event based watching for file descriptor changes  
instead of periodic checks; available with kqueue event method.

It’s intentionally left undocumented. Don’t use it, it’s  
unfinished code (there are known race which leads to SIGSEGV).

Maxim D.

---

<div class="post-metadata">

**Author:** ![Costello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bb73d2/32.png) [@Costello](https://www.ruby-forum.com/u/Costello)\
**Post date:** [May 12, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/what-does-open-file-cache-events-do/188462/3 "2010-05-12T14:31:03Z")

</div>

Oh, thanks a lot for the update Maxim, so helpful as always!

Though I think it would be better to document the directive, making sure  
to mention that it is not finished/not recommended to use!  
With no documentation, people might try to use it and have problems with  
it…

Again, thank you for the help.

Best regards,  
Costello

Posted at Nginx Forum:

> **[Re: What does open\_file\_cache\_events do?](https://forum.nginx.org/read.php?2,85785,85821#msg-85821)**
>
> Hello, I'm looking to document directives that are missing from the Wiki. I found loads in the source code, especially thanks to Manlio Perillo. I've stumbled upon "open\_file\_cache\_events" declared in ngx\_http\_core\_module.c. I investigated...
