Forum: Ruby on Rails rails equivalent to asp's Application object?

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.
Sas S. (Guest)
on 2006-04-11 19:52
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
Kevin O. (Guest)
on 2006-04-11 19:59
(Received via mailing list)
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
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


_Kevin
Tim C. (Guest)
on 2006-04-11 22:02
(Received via mailing list)
Just out of curiousity, what do you use use the Application object for?

Tim C.
removed_email_address@domain.invalid

On 11 Apr 2006 15:56:02 -0000, Kevin O.
Nuno (Guest)
on 2006-04-11 22:45
Tim C. wrote:
> Just out of curiousity, what do you use use the Application object for?
>

My guess is : system wide configuration options ?
Sas S. (Guest)
on 2006-04-12 04:57
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)
<xml>
<object>city</object>
<conditions>
  <condition>country_id=1</condition>
</conditions>
<user_id>234</user_id>
</xml>

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.
Tom M. (Guest)
on 2006-04-12 05:04
(Received via mailing list)
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. :-)

2) Modern DBs have caching built in.

3) Rails has caching built in.

--
-- Tom M.
Sas S. (Guest)
on 2006-04-12 05:17
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. :-)

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

> 2) Modern DBs have caching built in.

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

> 3) Rails has caching built in.

You're right, I'm being naughty, so I'll RTFM ;-)

> --
> -- Tom M.

Saludos

Sas
Kevin O. (Guest)
on 2006-04-12 07:18
(Received via mailing list)
Isn't that 3 things?


On Tuesday, April 11, 2006, at 6:03 PM, Tom M. wrote:
>> good guess...
>3) Rails has caching built in.
>
>--
>-- Tom M.
>
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


_Kevin
Tom M. (Guest)
on 2006-04-12 09:23
(Received via mailing list)
Sure is, I just couldn't stop writing!

:-)

--
-- Tom M.
Craig W. (Guest)
on 2006-04-12 17:18
(Received via mailing list)
I thought it was the result of premature optimization.

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