# Render :file cached?

**URL:** <https://www.ruby-forum.com/t/render-file-cached/178069>\
**Category:** Rails\
**Created:** [October 28, 2009, 7:55pm UTC](https://www.ruby-forum.com/t/render-file-cached/178069 "2009-10-28T19:55:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [October 28, 2009, 7:55pm UTC](https://www.ruby-forum.com/t/render-file-cached/178069/1 "2009-10-28T19:55:24Z")

</div>

In my application I have a controller/view that displays the contents  
of an audit log file

def audit\_log  
render :layout =\> ‘table’, :file =\> AUDIT\_LOG  
end

The audit log is updated frequently but the render call does not re-  
read the file so it gets stale. Is there a way to tell render to  
check the file timestamp and reload as needed?

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [October 28, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/render-file-cached/178069/2 "2009-10-28T21:30:13Z")

</div>

On Oct 28, 2:53 pm, Tony [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In my application I have a controller/view that displays the contents  
> of an audit log file
> 
> def audit\_log  
> render :layout =\> ‘table’, :file =\> AUDIT\_LOG  
> end
> 
> The audit log is updated frequently but the render call does not re-  
> read the file so it gets stale. Is there a way to tell render to  
> check the file timestamp and reload as needed?

Just posting some notes in case someone else runs into this.

It looks like caching happens when a layout is specified  
(for :text, :file and :inline). I wanted my layout so I’m off to try  
something new. :-\

from action\_view/base.rb  
def \_render\_with\_layout  
  
if (options[:inline] || options[:file] || options[:text])  
@cached\_content\_for\_layout = @content\_for\_layout  
render(:file =\> partial\_layout, :locals =\>  
local\_assigns)

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [October 28, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/render-file-cached/178069/3 "2009-10-28T21:56:33Z")

</div>

On Oct 28, 4:28 pm, Tony [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > read the file so it gets stale. Is there a way to tell render to  
> >   
> > if (options[:inline] || options[:file] || options[:text])  
> > @cached\_content\_for\_layout = @content\_for\_layout  
> > render(:file =\> partial\_layout, :locals =\>  
> > local\_assigns)

So…the solution is to just open the file directly instead of using  
render.

\<%= File.read(AUDIT\_LOG) %\>

I’ll probably cache it in the controller and only let it be updated  
once every X minutes.
