Data object stuck in L2 cache

2 posts, 1 answers
  1. Zdenek Plachy
    Zdenek Plachy avatar
    29 posts
    Member since:
    May 2007

    Posted 13 May 2012 Link to this post

    Hi,
    before all I must say Telerik OpenAccess is amazing ORM! I love to work with it.

    But... now I have problem with object deletion. I have three tables in MS SQL 2008 database in N:M relation. Files, Baskets and BasketFiles table. I'm sending screenshot from Visual Designer where is realtion clear.

    When I want to delete row from BasketFiles table, row is deleted, but still persists in cache. Another attempt to delete this object causes error. When I shut down L2 cache, everything is all right.

    Here is code causing problems (it is called in ItemCommand of RadGrid) I made code a little more verbose for clarity:
    Select Case e.CommandName
       Case "Delete"
         Dim basketFileToDeleteId = CInt(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("BasketFileId"))
         Dim basketFileToDelete = (From q In dc.BasketFiles Where q.BasketFileId = basketFileToDeleteId).FirstOrDefault
         dc.Delete(basketFileToDelete)
         dc.SaveChanges()

    Can you, please, tell me, where could be problem? I tried also clear cache with dc.Cache.Release and dc.Cache.Release(BasketFiles) command, but with no luck.

    Thank you,
    Zdenek
  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 15 May 2012 Link to this post

    Hi Zdenek Plachy,

    You should use the IObjectScope.Evict(entity) in order to remove entries from the second level cache:

    Select Case e.CommandName
       Case "Delete"
         Dim basketFileToDeleteId = CInt(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("BasketFileId"))
         Dim basketFileToDelete = (From q In dc.BasketFiles Where q.BasketFileId = basketFileToDeleteId).FirstOrDefault
         Dim key = dc.CreateObjectKey(entity)
         dc.LevelTwoCache.Evict(key)
         dc.Delete(basketFileToDelete)
         dc.SaveChanges()

    The IsCached(IObjectId) method can be used to check if the values for a certain object are cached.

    Hope that helps. If any other questions arise, do not hesitate to contact us back.

    All the best,
    Damyan Bogoev
    the Telerik team
    Follow @OpenAccessORM Twitter channel to get first the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
Back to Top