# Time based etags

**URL:** <https://www.ruby-forum.com/t/time-based-etags/195203>\
**Category:** Rails\
**Created:** [September 19, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/time-based-etags/195203 "2010-09-19T19:19:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 19, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/time-based-etags/195203/1 "2010-09-19T19:19:13Z")

</div>

In my app I am serving certain controller actions every x many  
minutes. For example, most popular posts are generated in memcached  
every 30 minutes and served from there.

I would like to use etags/last\_modified so that I am not even  
rendering the same “most\_popular” view for the same client within  
that 30 minute period. However I am not sure how to generate an etag  
or a last\_modified would suit this situation.

the flow would be something like.

#Posts controller

def index  
case ‘listing\_type’  
when ‘all\_posts’  
if stale?(:last\_modified =\> “timestamp that doesn’t  
change for 30 minutes”)  
@posts = get\_posts\_from\_memcached  
end  
end

Short of saving this timestamp to the db…how else can I create a  
last\_modified that time that works for this?
