Time based caching


#1

hi,

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

thanks in advance
onur


#2

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


#3

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.


#4

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


#5

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.


#6

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


#7

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


#8

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/referenced_page_caching/

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


#9

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.


#10

Maybe, this is what you are looking for:
http://hybridindie.com/2005/9/19/rubyonrailscaching

2005/11/19, Onur T.:


#11

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