Up Create, modify and delete

Take a snapshot

Last modified on August 15, 2012 17:21

You can take a snapshot of the entities in the entity cache and hold that snapshot as a potential rollback or restore point.


To work with the EntityManager's cache, use the CacheStateManager

Calling GetCacheState returns you an EntityCacheState that is a snapshot of the current state of the cache. You can also pass in a specific set of entities to be serialized into an EntityCacheState. You can hold on to multiple EntityCacheStates and if you need to rollback to one of them, just call RestoreCacheState.

 // Save the specified entities into an EntityCacheState
 EntityCacheState cache = manager.CacheStateManager.GetCacheState(entities);

 // Restore the cache state in the same or different EntityManager
 manager.CacheStateManager.RestoreCacheState(cache, RestoreStrategy.Normal);

You can also save the entity cache to a stream or file. See Save cache locally on how to do this.


The snapshot of an EntityManager's cache is called the EntityCacheState. The EntityCacheState can be restored by any EntityManager, so you can also use this to move entities between EntityManager's. Furthermore, the EntityCacheState is directly serializable so you can pass it as a parameter or object between tiers or even send it into a message queue.

Created by DevForce on February 16, 2011 16:10

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade