# Cache\_page does not work

**URL:** <https://www.ruby-forum.com/t/cache-page-does-not-work/105686>\
**Category:** Rails\
**Created:** [June 1, 2007, 11:11am UTC](https://www.ruby-forum.com/t/cache-page-does-not-work/105686 "2007-06-01T11:11:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawn\_shao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@shawn\_shao](https://www.ruby-forum.com/u/shawn_shao)\
**Post date:** [June 1, 2007, 11:11am UTC](https://www.ruby-forum.com/t/cache-page-does-not-work/105686/1 "2007-06-01T11:11:31Z")

</div>

## Hi guys: i got a problem on caching my pages: in my Sweeper i wrote:

class MySweeper \< ActionController::Caching::Sweeper  
observe Post

def after\_save(post)  
expire\_page(:controller =\> ‘post’, :action =\> ‘show’, :id =\>  
post.id)  
cache\_page(:controller =\> ‘post’, :action =\> ‘show’, :id =\>  
post.id)  
end

## end

The problem is ‘cache\_page’ NOT work while the ‘expire\_page’ works  
fine:  
when i open the url: /post/show/id , a cache page is created in public/  
post/show/ folder.  
then i edit the post, the cache page was cleared by the sweeper, but  
it does not be created until i reopen the show page url in brower.  
this problem occured in my controller too …

any help idea? or i just misunderstand the ‘cache\_page’ method?

thanks for help  
– shawn

---

<div class="post-metadata">

**Author:** ![shawn\_shao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@shawn\_shao](https://www.ruby-forum.com/u/shawn_shao)\
**Post date:** [June 1, 2007, 12:25pm UTC](https://www.ruby-forum.com/t/cache-page-does-not-work/105686/2 "2007-06-01T12:25:59Z")

</div>

shawn shao wrote:

> The problem is ‘cache\_page’ NOT work while the ‘expire\_page’ works  
> fine:  
> when i open the url: /post/show/id , a cache page is created in public/  
> post/show/ folder.  
> then i edit the post, the cache page was cleared by the sweeper, but  
> it does not be created until i reopen the show page url in brower.  
> this problem occured in my controller too …
> 
> any help idea? or i just misunderstand the ‘cache\_page’ method?
> 
> thanks for help  
> – shawn

The cache is only created when the acutla page is rendered again…

it works as intended…

---

<div class="post-metadata">

**Author:** ![shawn\_shao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@shawn\_shao](https://www.ruby-forum.com/u/shawn_shao)\
**Post date:** [June 1, 2007, 12:41pm UTC](https://www.ruby-forum.com/t/cache-page-does-not-work/105686/3 "2007-06-01T12:41:25Z")

</div>

Mikkel wrote:

> The cache is only created when the acutla page is rendered again…
> 
> it works as intended…

Thanks for reply, Mikkel~~

so is there any way i can generate a cache page without rendering the  
url page,  
Or can i ‘pretend’ rendering it after save() action in my controller?

---

<div class="post-metadata">

**Author:** ![shawn\_shao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@shawn\_shao](https://www.ruby-forum.com/u/shawn_shao)\
**Post date:** [June 1, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/cache-page-does-not-work/105686/4 "2007-06-01T17:38:31Z")

</div>

On 01 Jun 2007, at 12:41, Shawn Shao wrote:

> so is there any way i can generate a cache page without rendering the  
> url page,  
> Or can i ‘pretend’ rendering it after save() action in my controller?

Although I would advise against it, you could issue a “curl “+url\_for  
(…)+” \> /dev/null” using ruby’s system command to load the page.

Best regards

Peter De Berdt
