Caching Objects

  • Thread starter Thread starter matthias s.
  • Start date Start date
M

matthias s.

Hi there,

I'm writing a class which should hold some state information of my web
app. The class should be placed in the Cache for performance reasons.
But when the class gets removed from the cache (because its time has
expired), I'd like to persist the current state of the object to the
database.

Is it safe to place the code persisting the state to the db in the
destructor of the class?

Thanks in advance...
 
There are no destructors in .NET. What you're thinking about is the Finalizer.
In general the purpose of the Finalizer is to clean up any unmanaged resources
your class is holding onto. For your particular problem, I'd suggest using
the CacheItemRemoveCallback when Inserting the item into the cache. This
will notify you when the item is removed. This would be a good place to do
your persistence.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 

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


Back
Top