Syscache and Deleting a Recordset Issue

Topics: Core, Customizing Orchard
Jul 24, 2013 at 6:42 PM
I have upgraded to Orchard 1.7 and am using the Syscache module (nice module). It seems to be causing issues with the NogginBox.MailChimp module (another nice module). This question is not about the MailChimp module, it just serves as the example. In that module a recordset is deleted outside of the content manager. How can I tell Syscache to re-initiate the query rather than just take what is cached (as what is cached throws an error that the record is not there).

Here is the code that deletes using the repository:
_mergeVarsRepository.Delete(oldMergeVar);
I have tried "Flush" to reset the cache to no avail. It appears the cache issue is that the Part which is getting it's value from this repository does not know it has been changed (so SysCache is returning the part in it's last state). Because it is a Parent / Child hierarchy there is no way to use the Content Manager to accomplish the delete. Look forward to advice on the proper approach to managing:
  • Syscache
  • Deletion of a Child to cause cache reset
Aug 9, 2013 at 8:57 AM
I have the same problem as jao28, I using this example from Orchard Document
public void UpdateRewardsForContentItem(
            ContentItem item,
            IEnumerable<RewardProgramEntry> rewards) {

            var record = item.As<RewardsPart>().Record;
            var oldRewards = _contentRewardRepository.Fetch(
                r => r.RewardsPartRecord == record);
            var lookupNew = rewards
                .Where(e => e.IsChecked)
                .Select(e => e.RewardProgram)
                .ToDictionary(r => r, r => false);
            // Delete the rewards that are no longer there
            // and mark the ones that should stay
            foreach(var contentRewardProgramsRecord in oldRewards) {
                if (lookupNew.ContainsKey(
                    contentRewardProgramsRecord.RewardProgramRecord)) {

                    lookupNew[contentRewardProgramsRecord.RewardProgramRecord]
                        = true;
                }
                else {
                    _contentRewardRepository.Delete(contentRewardProgramsRecord);
                }
            }
            // Add the new rewards
            foreach(var reward in lookupNew.Where(kvp => !kvp.Value)
                                           .Select(kvp => kvp.Key)) {
                _contentRewardRepository.Create(new ContentRewardProgramsRecord {
                    RewardsPartRecord = record,
                    RewardProgramRecord = reward
                });
            }
        }
Each time I update the Content, it will redirect to Index. But if I go to Edit action again, this error occur
An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back

No row with the given identifier exists[RealEstate.Models.PropertyAdvantagePartRecordContent#12237]

NHibernate.ObjectNotFoundException: No row with the given identifier exists[RealEstate.Models.PropertyAdvantagePartRecordContent#12237] at NHibernate.Impl.SessionFactoryImpl.DefaultEntityNotFoundDelegate.HandleEntityNotFound(String entityName, Object id) at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) at Orchard.Data.Providers.AbstractDataServicesProvider.OrchardLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) in c:\Orchard\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs:line 130 at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) at NHibernate.Impl.SessionImpl.InternalLoad(String entityName, Object id, Boolean eager, Boolean isNullable) at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session) at NHibernate.Collection.PersistentBag.InitializeFromCache(ICollectionPersister persister, Object disassembled, Object owner) at NHibernate.Cache.Entry.CollectionCacheEntry.Assemble(IPersistentCollection collection, ICollectionPersister persister, Object owner) at NHibernate.Event.Default.DefaultInitializeCollectionEventListener.InitializeCollectionFromCache(Object id, ICollectionPersister persister, IPersistentCollection collection, ISessionImplementor source) at NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection(InitializeCollectionEvent event) at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing) at NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at RealEstate.Services.PropertyService.BuildEditViewModel(PropertyPart p) at RealEstate.Controllers.PropertyAdminController.Edit(Int32 id, String returnUrl) at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
After few minutes, I refresh Edit action, and it work again.

Anyone know the solution?
Coordinator
Aug 9, 2013 at 3:46 PM
Please file a bug.
Developer
Aug 9, 2013 at 10:24 PM
Oddness... Its almost like you have tried to save a record that you have also tried to delete....

Could you try optimising the code a little? I shortened it, should make things a little easier to read.
public void UpdateRewardsForContentItem(ContentItem item, IEnumerable<RewardProgramEntry> rewards) {
    var record = item.As<RewardsPart>().Record;
    var rewards = _contentRewardRepository.Fetch(r => r.RewardsPartRecord == record);
    
    foreach(var reward in rewards) {
        if (reward.IsChecked) {
            _contentRewardRepository.Create(new ContentRewardProgramsRecord {
                RewardsPartRecord = record,
                RewardProgramRecord = reward.RewardProgram
            });
        }
        else {
            _contentRewardRepository.Delete(reward);
        }
    }
}
Aug 10, 2013 at 2:45 AM
Edited Aug 10, 2013 at 2:46 AM
Thank for reply Jetski5822, but the code is from Orchard Document section, and its purpose is to delete what is not checked, and add what is checked but not exists in the records yet.

see http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations
Aug 13, 2013 at 11:36 AM
Anyone looking to track the effects of the bug filing can see it here: https://orchard.codeplex.com/workitem/20010

Thanks azltdanh for getting it posted.