Asp's application object rails equivalent?

In asp there’s a built’in object, Application, which behaves like the
session, but it allows you to share information among all users of the
application.

(http://www.microsoft.com/windows2000/en/server/IIs/default.asp?url=/windows2000/en/server/IIs/htm/asp/vbob6zkv.htm)

It’s just like if every user would be accessing the same session.

what is the rails equivalent?

And if there is no such thing, how would you implement such a thing?
(taking ito account that it would arouse some concurrency issues, in
fact asp’s Application object has a lock and unlock method for that
purpose

Saludos

Sas

There are a number of load-once files. A logical place is
environment.rb.
Consider placing something like this at the end of environment.rb:

Include your application configuration below

include ‘thread’
mutex = Mutex.new

module Settings
SETTINGS = {}
SETTINGS[:additional_snippets] = 5

def config(config_var)
mutex.synchronize do
SETTINGS[config_var]
end
end
end

Then in other code, include Settings and:

snippets = Settings::config(:additional_snippets)

I tested all except the mutex part.

View this message in context:
http://www.nabble.com/asp's-application-object-rails-equivalent--t1433258.html#a3867558
Sent from the RubyOnRails Users forum at Nabble.com.

Sorry. The concurrency code I originally posted won’t work. This appears
better.

Include your application configuration below

require ‘thread’

module Settings
MUTEX = Mutex.new
SETTINGS = {}
SETTINGS[:additional_snippets] = 5

def config(config_var)
MUTEX.synchronize do
SETTINGS[config_var]
end
end

def config=(var)
MUTEX.synchronize do
SETTINGS[config_var] = var
end
end
end

View this message in context:
http://www.nabble.com/asp's-application-object-rails-equivalent--t1433258.html#a3867871
Sent from the RubyOnRails Users forum at Nabble.com.

This was one of the original suggestions and is, in fact, how I am doing
it.
I have a settings table with two fields:

setting_name, :string
setting_value, :string

Here is the model:

class Setting < ActiveRecord::Base
def self.
return self.find_by_setting_name(index.to_s).setting_value
end

def self.[]=(index, value)
setting = self.find_by_setting_name(index.to_s)
setting.update_attribute(‘setting_value’, value)
end
end

With this I can do:

number_of_snippets = Setting[:article_paragraphs].to_i

A possible enhancement is to keep some type information so the explicit
conversion is not required.

View this message in context:
http://www.nabble.com/asp's-application-object-rails-equivalent--t1433258.html#a3873013
Sent from the RubyOnRails Users forum at Nabble.com.

On 12/04/2006, at 6:21 AM, s.ross wrote:

There are a number of load-once files. A logical place is
environment.rb.
Consider placing something like this at the end of environment.rb:

Of course, that won’t work with fastcgi, which uses a multi process
model, or an application server cluster. Either use the database or
Drb. I recommend the database, it’s easier, just create a settings
table and use a before_filter to get the records. Sure it’s an extra
query, but it shouldn’t matter for a decent DBMS.


Phillip H.
[email protected]
http://www.sitharus.com/

Thanks for the prompt answers

In fact, I was thinking about some way to implement a quick and dirty
cache system, specially for those little combo boxes that takes so many
trips to the DB to fill.

in this thread I explain what I had n mind (when I coulnd’t find the
original thread I thought I haven’t posted it at all… sorry for the
duplication)

http://www.ruby-forum.com/topic/61795#new

So, what would be the best way to implement such a thing???

I guess that if I keep the cache relatively small -invalidating it on a
time-elapsed or in a fixed lenght basis-, I can load it all on the first
access to the cache, and then in one trip to the db I would get several
items. Even thought I would be going to the DB, it would be an
improvement (well, that depends on wheter retrieving a hundred items in
one trip is faster thatn retrieving ten in ten trips)

Saludos

Sas

PS: Before you tell me, I promess I’ll study rails cache system :wink:

I’m in agreement with the poster who mentioned that optimizing should
wait
until you know you have a performance bottleneck. If you are really set
on a
cache, look into memcached
(Peak Obsession).
It might fit the bill.

View this message in context:
http://www.nabble.com/asp's-application-object-rails-equivalent--t1433258.html#a3875108
Sent from the RubyOnRails Users forum at Nabble.com.