gpt4 book ai didi

asp.net-mvc-3 - nHibernate 二级缓存,带有 memcached 和随机无效强制转换

转载 作者:行者123 更新时间:2023-12-04 12:41:49 32 4
gpt4 key购买 nike

我有一个 MVC3 应用程序使用 nHibernate 内存缓存 作为二级缓存提供者。我们间歇性地(但最近更频繁)遇到奇怪的类型转换问题。它是随机发生的,使 memcached 缓存无效将暂时解决问题。

它只发生在我们的生产环境中,因为我们不在其他环境中运行 memcached。但是,我在本地运行 memcached 并试图在没有运气的情况下在本地发生这种情况。

我们正在使用 Windows 上的 memcached 1.2.6 .这是堆栈跟踪。我知道这不足以确定任何事情,但是如果有人对我如何调试这个有任何想法,我们将不胜感激。我正在尝试在我们的生产机器上进行远程调试,但这是一年中的繁忙时间和风险。

Unable to cast object of type 'System.Int32' to type 'System.String'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.]
(Object , Object[] , SetterCallback ) +4270
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values) +80

[PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of MyApplication.Business.Data.Program]
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values) +207
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValues(Object entity, Object[] values) +97
NHibernate.Cache.Entry.CacheEntry.Assemble(Object[] values, Object result, Object id, IEntityPersister persister, IInterceptor interceptor, ISessionImplementor session) +306
NHibernate.Cache.Entry.CacheEntry.Assemble(Object instance, Object id, IEntityPersister persister, IInterceptor interceptor, ISessionImplementor session) +147
NHibernate.Event.Default.DefaultLoadEventListener.AssembleCacheEntry(CacheEntry entry, Object id, IEntityPersister persister, LoadEvent event) +434
NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent event, IEntityPersister persister, LoadType options) +800
NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +560
NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +229
NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +438
NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) +943
NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) +99
NHibernate.Impl.SessionImpl.Get(String entityName, Object id) +117
NHibernate.Impl.SessionImpl.Get(Object id) +70
MyApplication.Business.Repositories.Repository`1.Get(Object id) +148

最佳答案

我们遇到了同样的问题,我们已将问题定位为二级缓存中的无效缓存条目。在我们的例子中,当我们从缓存在二级缓存中的表/实体中添加或删除列/属性并部署更改时,就会出现问题。代码需要五列(为了参数),而缓存存储六列。

我们在存储库中采用的一种策略是捕获异常并使缓存无效。然后我们重试get。

    public override T Get(int id)
{
try
{
return base.Get(id);
}
catch (InvalidCastException)
{
_sessionFactory.EvictEntity(typeof (T).Name);
return Get(id);
}
}

希望这可以帮助!

关于asp.net-mvc-3 - nHibernate 二级缓存,带有 memcached 和随机无效强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15366842/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com