Nuno wrote:
Tim C. wrote:
Just out of curiousity, what do you use use the Application object for?
My guess is : system wide configuration options ?
good guess…
But in asp I used it to implement a quick and dirty cache system (yeah
yeah, I know, IT WON’T SCALE, but I use it for small amount of data)
I’ll tell you a little more.
Every acces to the DB goes thru an xml message. So I made a cahce system
so that I relate some of those message with a key
Imagine something like (i’m making it up, but it’ll let you understand)
city
country_id=1
<user_id>234</user_id>
This ends up calling some stored procedure like xmlCity_select
I save a cache item object with a key
“object:city,conditions:country_id=1” (I could use the whole xml message
if I ignored the user_id tag), the result of the query (which is another
xml) and an telling me it depends on the object city.
So whenever I create/update/delete a city, I have to tell the cache
system to get rid of every cache item depending on the object city.
Obviously, it only works is every modificaction goes thru my app.
Of course I don’t use it for every select clause, only for a few often
used tables (like filling combos, the first page of several tables, and
so on)
It was quite easy to implement, it tok only a couple of hours, because
I’ve already had a class that handles each and every xml request.
I though that it could be used in rails to implement some kind of cache
at the object level (whenever I issue a Country.find(24) go get it from
the Cache, if it wasn’t modified) and at the sql level, this time
comparing the whole sql sentence.
All you have to do is invalidate the cache when anything changes. If you
are caching more than one record, you have to do it on a table basis
(say you cached the first then records, and someone inserted one at the
beginning). It works great for statis or seldom changing data.
Please take into account that I’m only begining to experiment with
rails. And sometimes I wonder how can I acomplish things I’m used to do
in other environments.
So if you have any better ideas, please let me know.
I still coulnd’t study in depth the view-level cache system, but I think
it wouldn’t be so hard to implement it at the model or at the data
level.
Saludos and pardon the extension of this post
Sas
PS: This thing could be implemented in the session, on a per user basis,
but it would certainly be a waste of memory.