This is a migrated thread and some comments may be shown as answers.

Data object stuck in L2 cache

1 Answer 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Zdeněk
Top achievements
Rank 1
Zdeněk asked on 13 May 2012, 02:39 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 15 May 2012, 06:31 AM
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!
Tags
General Discussions
Asked by
Zdeněk
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or