Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 50aa7ef

Browse files
committed
adds cache expiration
1 parent 174fb12 commit 50aa7ef

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Solid.Identity.Protocols.Saml2p/Cache/Saml2pCache.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text;
77
using System.Text.Json;
88
using System.Text.Json.Serialization;
9+
using System.Text.Json.Serialization.Metadata;
910
using System.Threading.Tasks;
1011

1112
namespace Solid.Identity.Protocols.Saml2p.Cache
@@ -22,13 +23,13 @@ public Saml2pCache(IDistributedCache inner)
2223
public Task CacheRequestAsync(string key, AuthnRequest request)
2324
{
2425
var json = JsonSerializer.SerializeToUtf8Bytes(request);
25-
return _inner.SetAsync(key, json);
26+
return _inner.SetAsync(key, json, CreateOptions());
2627
}
2728

2829
public Task CacheStatusAsync(string key, Status status)
2930
{
3031
var json = JsonSerializer.SerializeToUtf8Bytes(status);
31-
return _inner.SetAsync($"{key}_status", json);
32+
return _inner.SetAsync($"{key}_status", json, CreateOptions());
3233
}
3334

3435
public async Task<AuthnRequest> FetchRequestAsync(string key)
@@ -52,5 +53,14 @@ public async Task RemoveAsync(string key)
5253
await _inner.RemoveAsync(key);
5354
await _inner.RemoveAsync($"{key}_status");
5455
}
56+
57+
private DistributedCacheEntryOptions CreateOptions()
58+
{
59+
return new DistributedCacheEntryOptions
60+
{
61+
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
62+
};
63+
}
64+
5565
}
5666
}

0 commit comments

Comments
 (0)