@@ -22,7 +22,6 @@ public CachingService(Lazy<ICacheProvider> cacheProvider)
22
22
this . cacheProvider = cacheProvider ?? throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
23
23
}
24
24
25
-
26
25
public CachingService ( Func < ICacheProvider > cacheProviderFactory )
27
26
{
28
27
if ( cacheProviderFactory == null ) throw new ArgumentNullException ( nameof ( cacheProviderFactory ) ) ;
@@ -37,38 +36,20 @@ public CachingService(ICacheProvider cache) : this(() => cache)
37
36
public static Lazy < ICacheProvider > DefaultCacheProvider { get ; set ; }
38
37
= new Lazy < ICacheProvider > ( ( ) => new MemoryCacheProvider ( ) ) ;
39
38
40
- /// <summary>
41
- /// Seconds to cache objects for by default
42
- /// </summary>
43
- public virtual int DefaultCacheDurationSeconds { get ; set ; } = 60 * 20 ;
44
-
45
39
/// <summary>
46
40
/// Seconds to cache objects for by default
47
41
/// </summary>
48
42
[ Obsolete ( "DefaultCacheDuration has been replaced with DefaultCacheDurationSeconds" ) ]
49
-
50
43
public virtual int DefaultCacheDuration
51
44
{
52
- get => DefaultCacheDurationSeconds ;
53
- set => DefaultCacheDurationSeconds = value ;
54
- }
55
-
56
- private DateTimeOffset DefaultExpiryDateTime => DateTimeOffset . Now . AddSeconds ( DefaultCacheDurationSeconds ) ;
57
-
58
- public virtual void Add < T > ( string key , T item )
59
- {
60
- Add ( key , item , DefaultExpiryDateTime ) ;
61
- }
62
-
63
- public virtual void Add < T > ( string key , T item , DateTimeOffset expires )
64
- {
65
- Add ( key , item , new MemoryCacheEntryOptions { AbsoluteExpiration = expires } ) ;
45
+ get => DefaultCachePolicy . DefaultCacheDurationSeconds ;
46
+ set => DefaultCachePolicy . DefaultCacheDurationSeconds = value ;
66
47
}
67
48
68
- public virtual void Add < T > ( string key , T item , TimeSpan slidingExpiration )
69
- {
70
- Add ( key , item , new MemoryCacheEntryOptions { SlidingExpiration = slidingExpiration } ) ;
71
- }
49
+ /// <summary>
50
+ /// Policy defining how long items should be cached for unless specified
51
+ /// </summary>
52
+ public virtual CacheDefaults DefaultCachePolicy { get ; set ; } = new CacheDefaults ( ) ;
72
53
73
54
public virtual void Add < T > ( string key , T item , MemoryCacheEntryOptions policy )
74
55
{
@@ -97,30 +78,6 @@ public virtual Task<T> GetAsync<T>(string key)
97
78
return UnwrapAsyncLazys < T > ( item ) ;
98
79
}
99
80
100
- public virtual T GetOrAdd < T > ( string key , Func < T > addItemFactory )
101
- {
102
- return GetOrAdd ( key , addItemFactory , DefaultExpiryDateTime ) ;
103
- }
104
-
105
- public virtual T GetOrAdd < T > ( string key , Func < T > addItemFactory , DateTimeOffset expires )
106
- {
107
- return GetOrAdd ( key , addItemFactory , new MemoryCacheEntryOptions { AbsoluteExpiration = expires } ) ;
108
- }
109
-
110
- public virtual T GetOrAdd < T > ( string key , Func < T > addItemFactory , TimeSpan slidingExpiration )
111
- {
112
- return GetOrAdd ( key , addItemFactory , new MemoryCacheEntryOptions { SlidingExpiration = slidingExpiration } ) ;
113
- }
114
-
115
- public virtual T GetOrAdd < T > ( string key , Func < T > addItemFactory , MemoryCacheEntryOptions policy )
116
- {
117
- return GetOrAdd ( key , entry =>
118
- {
119
- entry . SetOptions ( policy ) ;
120
- return addItemFactory ( ) ;
121
- } ) ;
122
- }
123
-
124
81
public virtual T GetOrAdd < T > ( string key , Func < ICacheEntry , T > addItemFactory )
125
82
{
126
83
ValidateKey ( key ) ;
@@ -162,33 +119,6 @@ public virtual void Remove(string key)
162
119
163
120
public virtual ICacheProvider CacheProvider => cacheProvider . Value ;
164
121
165
- public virtual Task < T > GetOrAddAsync < T > ( string key , Func < Task < T > > addItemFactory )
166
- {
167
- return GetOrAddAsync ( key , addItemFactory , DefaultExpiryDateTime ) ;
168
- }
169
-
170
- public virtual Task < T > GetOrAddAsync < T > ( string key , Func < Task < T > > addItemFactory , DateTimeOffset expires )
171
- {
172
- return GetOrAddAsync ( key , addItemFactory , new MemoryCacheEntryOptions { AbsoluteExpiration = expires } ) ;
173
- }
174
-
175
- public virtual Task < T > GetOrAddAsync < T > ( string key , Func < Task < T > > addItemFactory ,
176
- TimeSpan slidingExpiration )
177
- {
178
- return GetOrAddAsync ( key , addItemFactory ,
179
- new MemoryCacheEntryOptions { SlidingExpiration = slidingExpiration } ) ;
180
- }
181
-
182
- public virtual Task < T > GetOrAddAsync < T > ( string key , Func < Task < T > > addItemFactory ,
183
- MemoryCacheEntryOptions policy )
184
- {
185
- return GetOrAddAsync ( key , entry =>
186
- {
187
- entry . SetOptions ( policy ) ;
188
- return addItemFactory ( ) ;
189
- } ) ;
190
- }
191
-
192
122
public virtual async Task < T > GetOrAddAsync < T > ( string key , Func < ICacheEntry , Task < T > > addItemFactory )
193
123
{
194
124
ValidateKey ( key ) ;
0 commit comments