I forgot one small thing, when your user logs out, don't forget to delete
his/her username: cookies.delete('username')
- Matt
On Sat, Jul 9, 2011 at 11:45 AM, Matt Aimonetti <[email protected]>wrote:
> The best article I read was this one:
> http://tomayko.com/writings/things-caches-do It really explains well how
> caching works.
>
> Quick and dirty list of controller helpers for Rails:
>
> @cinema = Cinema.find(params[:id])
> if stale?(:last_modified => @cinema.updated_at.utc, :etag => @cinema)
> expires_in 5.minutes, :public => true
> end
>
> guide:
> http://guides.rubyonrails.org/caching_with_rails.html#conditional-get-support
>
> For the JS it's quite straight forward, a good example would be:
> http://theshownation.com/ (look at the JS source and the DOM)
>
> Here is the part you care about: https://gist.github.com/1073832
> You can't use the session since the page is cached, so instead what you do
> is when the user logs in, you set another cookie with the username for
> instance.
> In your controller it would like something like: cookies[:username]
> session[:username]
> Then when the DOM is loaded, you call a handler function such as
> handleCachedUserLinks() in the example above.
> The handler gets the username from the cookie and then changes the DOM
> accordingly and makes an ajax call to get the extra data needed if it's not
> stored in the cookie.
>
> You should start by doing the JS part and once you have that up and
> running, turn on the caching (literally 2 or 3 lines of code per action
> max). In dev mode, if you don't want to setup nginx + varnish, you can use
> rack-cache.
>
> I hope that helps,
>
> - Matt
>
>
> On Sat, Jul 9, 2011 at 10:00 AM, Patrick Crowley <[email protected]>wrote:
>
>> Hey, folks.
>>
>> I'm adding varnish-based caching support to my app.
>>
>> If this is going to work, though, I need to update our user greeting to
>> work via javascript so we can dynamically add the user greeting to the
>> static logged-out version of our pages that we're caching.
>>
>> Do you know any good blog posts or docs for this?
>>
>> Here are a few more details about the app:
>> - Rails 2.3.10 on Ruby 1.8.7
>> - Clearance for authentication
>> - Hosted on Heroku
>>
>> Cheers,
>> Patrick
>>
>> --
>> SD Ruby mailing list
>> [email protected]
>> http://groups.google.com/group/sdruby
>
>
>
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby