Rails equivalent to asp's Application object?

In asp you have an Application built-in object, which works just like
the Session hash, but it lets you share information among all users of a
given application.

which is the rails equivalent???

and if there isn’t, how would you implement such a thing ? (there would
be concurrency issues to take into account, in fact asp’s application
object has some lock and unlock methods to accomplish that)

Saludos

Sas

If you want globally visible data, why not just store it in a database
table and load it when needed?

On Tuesday, April 11, 2006, at 5:52 PM, sas sas wrote:

Saludos

Sas


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

Just out of curiousity, what do you use use the Application object for?

Tim C.
[email protected]

On 11 Apr 2006 15:56:02 -0000, Kevin O.

Tim C. wrote:

Just out of curiousity, what do you use use the Application object for?

My guess is : system wide configuration options ?

On Apr 11, 2006, at 5:57 PM, sas sas wrote:

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)

Two things:

  1. Premature optimization is the hobgoblin of little minds. :slight_smile:

  2. Modern DBs have caching built in.

  3. Rails has caching built in.


– Tom M.

Tom M. wrote:

On Apr 11, 2006, at 5:57 PM, sas sas wrote:

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)

Two things:

  1. Premature optimization is the hobgoblin of little minds. :slight_smile:

I grant you it’s really premature now… it wasn’t when I had to
implement it with asp…

  1. Modern DBs have caching built in.

Yeap, but the data still has to go from one tier to another

  1. Rails has caching built in.

You’re right, I’m being naughty, so I’ll RTFM :wink:


– Tom M.

Saludos

Sas

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.

Sure is, I just couldn’t stop writing!

:slight_smile:


– Tom M.

Isn’t that 3 things?

On Tuesday, April 11, 2006, at 6:03 PM, Tom M. wrote:

good guess…

  1. Rails has caching built in.


– Tom M.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

I thought it was the result of premature optimization.

Craig