Skip to content

Commit

Permalink
Use Generic type rather than object (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
gamblen authored Sep 1, 2021
1 parent 33d055c commit b6e6f74
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,8 @@ public void TryGetReturnsCachedValueAndTrue()
var contains2 = sut.TryGetValue<string>("invalidkey", out var value2);

Assert.IsFalse(contains2);

Assert.Throws<InvalidCastException>(() => sut.TryGetValue<int>(key, out var value3));
}
}
}
2 changes: 1 addition & 1 deletion LazyCache/CachingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public virtual Task<T> GetAsync<T>(string key)
return GetValueFromAsyncLazy<T>(item, out _);
}

public virtual bool TryGetValue<T>(string key, out object value)
public virtual bool TryGetValue<T>(string key, out T value)
{
ValidateKey(key);

Expand Down
2 changes: 1 addition & 1 deletion LazyCache/IAppCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IAppCache
void Add<T>(string key, T item, MemoryCacheEntryOptions policy);
T Get<T>(string key);
Task<T> GetAsync<T>(string key);
bool TryGetValue<T>(string key, out object value);
bool TryGetValue<T>(string key, out T value);

T GetOrAdd<T>(string key, Func<ICacheEntry, T> addItemFactory);
T GetOrAdd<T>(string key, Func<ICacheEntry, T> addItemFactory, MemoryCacheEntryOptions policy);
Expand Down
2 changes: 1 addition & 1 deletion LazyCache/ICacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface ICacheProvider : IDisposable
object GetOrCreate<T>(string key, MemoryCacheEntryOptions policy, Func<ICacheEntry, T> func);
void Remove(string key);
Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> func);
bool TryGetValue(object key, out object value);
bool TryGetValue<T>(object key, out T value);
}
}
2 changes: 1 addition & 1 deletion LazyCache/Mocks/MockCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> func)
return func(null);
}

public bool TryGetValue(object key, out object value)
public bool TryGetValue<T>(object key, out T value)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion LazyCache/Mocks/MockCachingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Add<T>(string key, T item, MemoryCacheEntryOptions policy)
{
}

public bool TryGetValue<T>(string key, out object value)
public bool TryGetValue<T>(string key, out T value)
{
value = default(T);
return true;
Expand Down
2 changes: 1 addition & 1 deletion LazyCache/Providers/MemoryCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> factor
return cache.GetOrCreateAsync(key, factory);
}

public bool TryGetValue(object key, out object value)
public bool TryGetValue<T>(object key, out T value)
{
return cache.TryGetValue(key, out value);
}
Expand Down

0 comments on commit b6e6f74

Please sign in to comment.