Caching Objects

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...
 
B

Brock Allen

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.
 

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

Caching objects 2
Browser Game Caching and Design 1
Leverage browser caching 2
Caching App Data 1
Data caching question 3
Disabling page caching not working 2
Caching question 1
Caching architecture question. 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top