-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid caching MediaTypeHeaderValue that is not serializable #165
Comments
I saw now that should be enough to cache this MediaTypeHeaderValue contenttype = null;
var ct = _webApiCache.Get<string>(cachekey + Constants.ContentTypeKey);
if (ct != null)
{
if (!MediaTypeHeaderValue.TryParse(ct, out contenttype))
{
contenttype = new MediaTypeHeaderValue(cachekey.Split(new[] { ':' }, 2)[1].Split(';')[0]);
}
} and var contentType = responseContent.Headers.ContentType.ToString();
_webApiCache.Add(cachekey + Constants.ContentTypeKey,
contentType,
cacheTime.AbsoluteExpiration, baseKey); |
I've submitted a PR to fix this |
I need that PR to be merged or discussed to have a working implementation of AppFabric provider: https://github.com/micdenny/Strathweb.CacheOutput.WebApi2.AppFabric |
+1 writing a redis provider, same root issue. |
This happened because MediaTypeHeaderValue has read only properties and depending on your Lib which is serializing, for example JSON.NET, custom JsonConverter is needed. |
I have run into this issue as well trying to implement a FileCache option, any eta? |
In general every class that is not a POCO class should not be cached, otherwise it becomes difficult to implement a caching provider based on a distributed caching system.
I'm developing an extension for AppFabric (the same will be when I will implement the Redis extension), and I'm blocked because
CacheOutputAttribute
tries to put in cache a .net framework objectMediaTypeHeaderValue
that is not serializable.If caching that whole object is necessary we should think to use a POCO class instead, that share the same structure:
The text was updated successfully, but these errors were encountered: