By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Cache_dependency_used_more_that_once Exception when adding to .NET cache

P: n/a
Hi,

I'm trying to add an object to the .NET cache using a CacheDependency
and I get the following exception :

System.InvalidOperationException: Cache_dependency_used_more_that_once
at System.Web.Caching.CacheEntry.MonitorDependencyCha nges()
at System.Web.Caching.CacheSingle.UpdateCache(CacheKe y cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheMultiple.UpdateCache(Cache Key cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic,
String key, Object value, CacheDependency dependencies, DateTime
utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority
priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace)
at System.Web.Caching.Cache.Insert(String key, Object value,
CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan
slidingExpiration, CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback)

I've not seen this error before...and I couldn't find reference to
this error message either on Google or MSDN.
Does anyone know what could cause the
"Cache_dependency_used_more_that_once" exception to happen.

Thanks
Mahesh

Feb 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Decompiled:

internal void MonitorDependencyChanges()
{
CacheDependency dependency1 = this._dependency;
if ((dependency1 != null) && (this.State ==
CacheEntry.EntryState.AddedToCache))
{
if (!dependency1.Use())
{
throw new
InvalidOperationException(SR.GetString("Cache_depe ndency_used_more_that_once"));
}
dependency1.SetCacheDependencyChanged(this);
}
}

In other words, it is trying to use the dependency but it is alread in use
(probably from another part of your code is my guess).
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ma***********@gmail.com" wrote:
Hi,

I'm trying to add an object to the .NET cache using a CacheDependency
and I get the following exception :

System.InvalidOperationException: Cache_dependency_used_more_that_once
at System.Web.Caching.CacheEntry.MonitorDependencyCha nges()
at System.Web.Caching.CacheSingle.UpdateCache(CacheKe y cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheMultiple.UpdateCache(Cache Key cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic,
String key, Object value, CacheDependency dependencies, DateTime
utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority
priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace)
at System.Web.Caching.Cache.Insert(String key, Object value,
CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan
slidingExpiration, CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback)

I've not seen this error before...and I couldn't find reference to
this error message either on Google or MSDN.
Does anyone know what could cause the
"Cache_dependency_used_more_that_once" exception to happen.

Thanks
Mahesh

Feb 16 '07 #2

P: n/a
Hi Peter,

Thanks for the reply! I was doing the following :

_cache.Insert("dep","dependency");

string[] depKey = {"dep"};
CacheDependency cdep = new CacheDependency(null,depKey);

_cache.Insert("1","one",cdep,...);
_cache.Insert("2","two",cdep,..);

I thought we could use the same CacheDependency object for more than
one keys; seems like we cannot (btw it would be interesting to know
why it was designed this way)
The code worked after I changed to this...

_cache.Insert("dep","dependency");
string[] depKey = {"dep"};

CacheDependency cdep1 = new CacheDependency(null,depKey);
_cache.Insert("1","one",cdep1,...);

CacheDependency cdep2 = new CacheDependency(null,depKey);
_cache.Insert("2","two",cdep2,..);

Thanks again for your help.

-Mahesh

On Feb 16, 1:10 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Decompiled:

internal void MonitorDependencyChanges()
{
CacheDependency dependency1 = this._dependency;
if ((dependency1 != null) && (this.State ==
CacheEntry.EntryState.AddedToCache))
{
if (!dependency1.Use())
{
throw new
InvalidOperationException(SR.GetString("Cache_depe ndency_used_more_that_once"));
}
dependency1.SetCacheDependencyChanged(this);
}

}

In other words, it is trying to use the dependency but it is alread in use
(probably from another part of your code is my guess).
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"mahesh.pra...@gmail.com" wrote:
Hi,
I'm trying to add an object to the .NET cache using a CacheDependency
and I get the following exception :
System.InvalidOperationException: Cache_dependency_used_more_that_once
at System.Web.Caching.CacheEntry.MonitorDependencyCha nges()
at System.Web.Caching.CacheSingle.UpdateCache(CacheKe y cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheMultiple.UpdateCache(Cache Key cacheKey,
CacheEntry newEntry, Boolean replace, CacheItemRemovedReason
removedReason, Object& valueOld)
at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic,
String key, Object value, CacheDependency dependencies, DateTime
utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority
priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace)
at System.Web.Caching.Cache.Insert(String key, Object value,
CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan
slidingExpiration, CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback)
I've not seen this error before...and I couldn't find reference to
this error message either on Google or MSDN.
Does anyone know what could cause the
"Cache_dependency_used_more_that_once" exception to happen.
Thanks
Mahesh

Feb 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.