Skip to content

Commit 9609017

Browse files
committed
obsolete Get() in favor of Get<T> on IApiOutputCache
1 parent f7cd52d commit 9609017

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/WebApi.OutputCache.Core/Cache/IApiOutputCache.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ namespace WebApi.OutputCache.Core.Cache
66
public interface IApiOutputCache
77
{
88
void RemoveStartsWith(string key);
9+
910
T Get<T>(string key) where T : class;
11+
12+
[Obsolete("Use Get<T> instead")]
1013
object Get(string key);
14+
1115
void Remove(string key);
16+
1217
bool Contains(string key);
18+
1319
void Add(string key, object o, DateTimeOffset expiration, string dependsOnKey = null);
20+
1421
IEnumerable<string> AllKeys { get; }
1522
}
1623
}

src/WebApi.OutputCache.Core/Cache/MemoryCacheDefault.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public T Get<T>(string key) where T : class
2323
return o;
2424
}
2525

26+
[Obsolete("Use Get<T> instead")]
2627
public object Get(string key)
2728
{
2829
return Cache.Get(key);

src/WebApi.OutputCache.V2/CacheOutputAttribute.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
150150

151151
if (actionContext.Request.Headers.IfNoneMatch != null)
152152
{
153-
var etag = _webApiCache.Get(cachekey + Constants.EtagKey) as string;
153+
var etag = _webApiCache.Get<string>(cachekey + Constants.EtagKey);
154154
if (etag != null)
155155
{
156156
if (actionContext.Request.Headers.IfNoneMatch.Any(x => x.Tag == etag))
@@ -164,16 +164,16 @@ public override void OnActionExecuting(HttpActionContext actionContext)
164164
}
165165
}
166166

167-
var val = _webApiCache.Get(cachekey) as byte[];
167+
var val = _webApiCache.Get<byte[]>(cachekey);
168168
if (val == null) return;
169169

170-
var contenttype = _webApiCache.Get(cachekey + Constants.ContentTypeKey) as MediaTypeHeaderValue ?? new MediaTypeHeaderValue(cachekey.Split(new[] {':'},2)[1]);
170+
var contenttype = _webApiCache.Get<MediaTypeHeaderValue>(cachekey + Constants.ContentTypeKey) ?? new MediaTypeHeaderValue(cachekey.Split(new[] {':'},2)[1]);
171171

172172
actionContext.Response = actionContext.Request.CreateResponse();
173173
actionContext.Response.Content = new ByteArrayContent(val);
174174

175175
actionContext.Response.Content.Headers.ContentType = contenttype;
176-
var responseEtag = _webApiCache.Get(cachekey + Constants.EtagKey) as string;
176+
var responseEtag = _webApiCache.Get<string>(cachekey + Constants.EtagKey);
177177
if (responseEtag != null) SetEtag(actionContext.Response, responseEtag);
178178

179179
var cacheTime = CacheTimeQuery.Execute(DateTime.Now);

test/WebApi.OutputCache.V2.Tests/ServerSideTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void no_caching_if_user_authenticated_and_flag_set_to_off()
237237
public void etag_match_304_if_none_match()
238238
{
239239
_cache.Setup(x => x.Contains(It.Is<string>(i => i.Contains("etag_match_304")))).Returns(true);
240-
_cache.Setup(x => x.Get(It.Is<string>(i => i.Contains("etag_match_304") && i.Contains(Constants.EtagKey))))
240+
_cache.Setup(x => x.Get<string>(It.Is<string>(i => i.Contains("etag_match_304") && i.Contains(Constants.EtagKey))))
241241
.Returns(@"""abc""");
242242

243243
var client = new HttpClient(_server);
@@ -254,8 +254,9 @@ public void etag_match_304_if_none_match()
254254
public void etag_not_match_304_if_none_match()
255255
{
256256
_cache.Setup(x => x.Contains(It.Is<string>(i => i.Contains("etag_match_304")))).Returns(true);
257-
_cache.Setup(x => x.Get(It.Is<string>(i => i.Contains("etag_match_304") && i.Contains(Constants.EtagKey))))
258-
.Returns((object)new EntityTagHeaderValue(@"""abcdef"""));
257+
_cache.Setup(x => x.Get<byte[]>(It.IsAny<string>())).Returns((byte[])null);
258+
_cache.Setup(x => x.Get<string>(It.Is<string>(i => i.Contains("etag_match_304") && i.Contains(Constants.EtagKey))))
259+
.Returns(@"""abcdef""");
259260

260261
var client = new HttpClient(_server);
261262
var req = new HttpRequestMessage(HttpMethod.Get, _url + "etag_match_304");

0 commit comments

Comments
 (0)