Global Count Variable

I would like to set up a global variable to count how many times a
specific method is executed, but I would like the variable to keep
counting regardless of sessions, restarting the app, etc. Is this
possible?

Or… I could just do a simple read/write to a text file on the server,
but I’m not finding any good tutorials or examples about simple text
i/o… any suggestions?

Thanks!
-stirman

you could create another table with one record that you load and
increase using the rails Find and Save methods for the Model.

Seems like a lot of cpu time and effort increase an int variable, right?

Or would text file i/o be comparable?

Thanks for the suggestion, I appreciate it!

-stirman

you could create another table with one record that you load and
increase using the rails Find and Save methods for the Model.

It will take as much time, probably less, to update a field in the
database than to update and save to a file by hand. Besides, is the site
going to be that busy that you need to take into account system
resources?

Jason

On 6/19/06, Jason S. [email protected] wrote:

Seems like a lot of cpu time and effort increase an int variable, right?

Or would text file i/o be comparable?

Nice thing about the database method is if you put a bit 'o metadata
in there you can use the same ActiveRecord model for incrementing
other stuff. It will likely come down the pipes anyway… :slight_smile: I use
a similar mechanism to track “ad” impressions / hits… :: shrug ::
Performance is fine.

-Curtis

I agree using a table/record is the best approach. But if you really
want to
use a file, then use the IO.File class in Ruby to open/read/write the
file.

For details look here: http://ruby.outertrack.com/class/IO

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs