mod_ruby object persistence

T

tsuraan

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 =3D 0
end

def get()
@counter +=3D 1
end
end
-----
and counter.rhtml:
-----
<html>
<body>
<% require 'countersingle' %>
<%=3D 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?
 
E

Eric Hodel

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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top