Caching Objects

Discussion in 'ASP .Net' started by matthias s., Jun 9, 2005.

  1. matthias s.

    matthias s. Guest

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

    Kind regards!

    /matthias
     
    matthias s., Jun 9, 2005
    #1
    1. Advertising

  2. matthias s.

    Brock Allen Guest

    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



    > 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...
    >
    > /matthias
    >
     
    Brock Allen, Jun 9, 2005
    #2
    1. Advertising

  3. matthias s.

    matthias s. Guest

    thanks brock, I'll give it a try!

    Kind regards!

    /matthias

    Brock Allen wrote:
    > 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
    >
    >
    >
    >> 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...
    >>
    >> /matthias
    >>

    >
    >
    >
     
    matthias s., Jun 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    454
  2. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    828
    Troy Simpson
    Jan 19, 2004
  3. 7stud
    Replies:
    11
    Views:
    730
    Dennis Lee Bieber
    Mar 20, 2007
  4. News123
    Replies:
    7
    Views:
    393
    Dave Angel
    Jun 29, 2009
  5. JimLad
    Replies:
    3
    Views:
    942
    JimLad
    Jan 21, 2010
Loading...

Share This Page