# Member auth and caching

**URL:** <https://www.ruby-forum.com/t/member-auth-and-caching/115522>\
**Category:** Radiant CMS\
**Created:** [September 25, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/member-auth-and-caching/115522 "2007-09-25T23:40:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [September 25, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/member-auth-and-caching/115522/1 "2007-09-25T23:40:32Z")

</div>

I’m working on a site that will have a membership area that will  
require login. I’m a sucker for caching, and all the solutions I’ve  
seen so far disable the cache to get auth working. I haven’t dug in  
deep into this idea yet, but I’m pondering the value of tweaking  
ResponseCache to store something like an auth\_required value in the  
YML file and returning auth\_required pages from the cache only if a  
user is logged-in. That way logged-in users get the benefit of  
cached pages.

Non-logged-in folks won’t get the cached page, so they’ll have the  
page dynamically loaded and get caught by the ‘hey-you-log-in-first’  
routine.

Are there any major reasons against the idea?

basically, it would look like this…

## there will be a before\_filter on SiteController to establish the

value of logged\_in

def read\_metadata(path, logged\_in)  
#added a parameter  
path = clean(path)  
name = “#{page\_cache\_path(path)}.yml”  
if File.exists?(name) and not File.directory?(name)  
content = File.open(name,“rb”) { |f| f.read }  
metadata = YAML::load(content)  
auth\_required = metadata[‘auth\_required’] #added  
if(metadata[‘expires’] && metadata[‘expires’] \>= Time.now && (!  
auth\_required || (auth\_required && logged\_in)) #updated  
return metadata  
end  
end  
end

def response\_cached?(path, logged\_in = false) #added a  
parameter  
!!read\_metadata(path, logged\_in)  
#here too  
end

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [September 30, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/member-auth-and-caching/115522/2 "2007-09-30T18:43:26Z")

</div>

It should work. Just be careful not to customize the page with  
some specific login information, the cached version will be shared by  
all users.

```
 /AITOR
```
