Forum: Ruby on Rails time based caching

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
onurturgay (Guest)
on 2005-11-19 22:28
(Received via mailing list)
hi,

how can I expire my cached fragments or pages based on time?

thanks in advance
onur
technoweenie (Guest)
on 2005-11-19 22:33
(Received via mailing list)
On 11/19/05, Onur T. <removed_email_address@domain.invalid> wrote:
> hi,
>
> how can I expire my cached fragments or pages based on time?
>
> thanks in advance
> onur

Use a cron job.  Look at the last modified dates of the files.

--
rick
http://techno-weenie.net
onurturgay (Guest)
on 2005-11-19 22:42
(Received via mailing list)
in php::pear simplecache I could define an expiration date for each
cache
fiel that I create. So that I didnt violate DRY. If I create cache
somewhere
but check for it elsewhere I kind of repeat my self.
technoweenie (Guest)
on 2005-11-19 22:59
(Received via mailing list)
On 11/19/05, Onur T. <removed_email_address@domain.invalid> wrote:
> in php::pear simplecache I could define an expiration date for each cache
> fiel that I create. So that I didnt violate DRY. If I create cache somewhere
> but check for it elsewhere I kind of repeat my self.

Isn't it more dry to use the OS to find and remove old files?

At any rate, write a plugin or something to do what you want.  I'm
guessing no one's really needed the feature bad enough to implement
it.
--
rick
http://techno-weenie.net
ezra (Guest)
on 2005-11-19 23:44
(Received via mailing list)
On Nov 19, 2005, at 12:28 PM, Onur T. wrote:

> hi,
>
> how can I expire my cached fragments or pages based on time?
>
> thanks in advance
> onur

The easiest way is to use a cron job to either run a script with
script/runner that will expire the cached pages. Or you can just have
the cron job erase the cached pages in your public directory,

HTH-

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732
onurturgay (Guest)
on 2005-11-20 00:41
(Received via mailing list)
For example my latest comments fragment must be expired in 5 minutes.
But my
tagcloud must be expired in 1 day. If i code this one by one into a cron
job, that'll be unmaintainable.

my solution is holding all my caches in database (id, cache_file_name,
expire_at) and run a cron job that calls the ubry script that checks
this
table and expires fragments when necessary.
bruno.celeste (Guest)
on 2005-11-20 02:35
(Received via mailing list)
Maybe, this is what you are looking for:
http://hybridindie.com/2005/9/19/rubyonrailscaching

2005/11/19, Onur T.:
steve (Guest)
on 2005-11-20 04:12
(Received via mailing list)
On Nov 19, 2005, at 2:39 PM, Onur T. wrote:

> If i code this one by one into a cron job, that'll be unmaintainable.

Nah..  how is it any less maintainable than doing it any other
way???  I say don't make things complicated.

man find

look at -[acm]time OR -[acm]min, and -delete

oh, and BE CAREFUL (i.e. test with -print before using -delete).

--Steve
technoweenie (Guest)
on 2005-11-20 05:00
(Received via mailing list)
On 11/19/05, Onur T. <removed_email_address@domain.invalid> wrote:
> For example my latest comments fragment must be expired in 5 minutes. But my
> tagcloud must be expired in 1 day. If i code this one by one into a cron
> job, that'll be unmaintainable.
>
> my solution is holding all my caches in database (id, cache_file_name,
> expire_at) and run a cron job that calls the ubry script that checks this
> table and expires fragments when necessary.

I just wrote this plugin today for something else, but it may work for
you too:

http://techno-weenie.net/svn/projects/plugins/refe...

Referenced Page Caching is a small wrapper around Rails' page caching.
 It allows you to add references to a current page's cache file.

These references are then used to expire all the pages that are
referenced when it is modified or destroyed.

--
rick
http://techno-weenie.net
onurturgay (Guest)
on 2005-11-20 12:07
(Received via mailing list)
whenever I create a new cache type, I will have to go to the cron job
and
add a sweeping action for it including its expiry time (as every file
can
have different lifetimes). I think its much more maintainable when you
specify the expiry time wherever you define the cache.
Jérôme Lipowicz (Guest)
on 2006-05-04 01:31
(Received via mailing list)
On 11/19/05, Ezra Z. <removed_email_address@domain.invalid> wrote:

> The easiest way is to use a cron job to either run a script with
> script/runner that will expire the cached pages. Or you can just have
> the cron job erase the cached pages in your public directory,

Hello railers

I'm also trying to delete some caching every hour.

I've set a cron job for executing every hour

/home/www/script/runner 'ActionController::Caching::Pages.expire_page(
:controller => "home", :action => "index" )' -e production

but it raises an error:
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.1/lib/commands/runner.rb:27:
undefined method `expire_page' for
ActionController::Caching::Pages:Module (NoMethodError)

Any idea ?

Thanks
This topic is locked and can not be replied to.