Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mod_ruby object persistence

0 views
Skip to first unread message

tsuraan

unread,
Oct 27, 2005, 9:58:28 AM10/27/05
to
How long do objects stick around in mod_ruby? I have a really simple
pair of files:

countersingle.rb:
-----
require 'singleton'

class Counter
include Singleton
def initialize()
@counter = 0
end

def get()
@counter += 1
end
end
-----
and counter.rhtml:
-----
<html>
<body>
<% require 'countersingle' %>
<%= Counter.instance.get %>
</body>
</html>
-----

When I am refreshing the page, the count goes up. If I wait a minute
or so, the count gets reset to zero. So, I'm wondering if there's
some way to force persistence with mod_ruby, or is there a garbage
collection that happens after a minute of inactivity that will always
clear up everything that's not relevent anymore?


Eric Hodel

unread,
Oct 27, 2005, 4:05:43 PM10/27/05
to

A class will stay around as long as its apache process is alive. Of
course, if you go to a different apache process you'll have a
different class. You'll need a global-to-the-machine place to store
your counter if you want it to work right.

--
Eric Hodel - drb...@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


0 new messages