memcached-providers icon indicating copy to clipboard operation
memcached-providers copied to clipboard

System.ArgumentException: Keys cannot contain the chars 0x00-0x20 and space.

Open tlianza opened this issue 13 years ago • 1 comments

When using the Memcached output provider, and enabling static file output caching in IIS, I wind up getting a lot of exceptions like this, for simple files that should 404. Ex. bots will request content with bad characters in it, and instead of returning a 404, the server winds up returning a 500.

Any ideas for a good workaround for this? I understand if memcached is limited in the characters it might accept for keys, but it seems to me like perhaps the outputcache provider's "Get" implementation might be better served to return the fact that it doesn't have content for that key, rather than throwing an exception. But, perhaps there are ramifications I'm not considering.

Thanks, Tom

System.ArgumentException: Keys cannot contain the chars 0x00-0x20 and space.
   at Enyim.Caching.Memcached.DefaultKeyTransformer.Transform(String key) in d:\Dropbox\repo\EnyimMemcached\Enyim.Caching\Memcached\KeyTransformers\DefaultKeyTransformer.cs:line 22
   at Membase.MembaseClient.PerformTryGet(String key, UInt64& cas, Object& value) in d:\Dropbox\repo\EnyimMemcached\Membase\MembaseClient.cs:line 85
   at Enyim.Caching.MemcachedClient.TryGet(String key, Object& value) in d:\Dropbox\repo\EnyimMemcached\Enyim.Caching\MemcachedClient.cs:line 132
   at Enyim.Caching.MemcachedClient.Get(String key) in d:\Dropbox\repo\EnyimMemcached\Enyim.Caching\MemcachedClient.cs:line 107
   at System.Web.Caching.OutputCache.Get(String key)
   at System.Web.Caching.OutputCacheModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

tlianza avatar Nov 06 '11 05:11 tlianza

I just noticed the various keyTransformers ( documented here: https://github.com/enyim/EnyimMemcached/wiki/MemcachedClient-Configuration )

Seems like one of the hashing transformers, like the TigerHashKeyTransformer will do the trick. However, is there a way to use a different key transformer when doing output caching versus the other operations? Would be nice. For now, I have this line inside the config and it looks like it's doing the trick:

 <keyTransformer type="Enyim.Caching.Memcached.TigerHashKeyTransformer, Enyim.Caching" />

tlianza avatar Jan 04 '12 21:01 tlianza