Skip to content

Commit

Permalink
adds cache expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
gislikonrad committed Nov 5, 2024
1 parent 174fb12 commit 50aa7ef
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Solid.Identity.Protocols.Saml2p/Cache/Saml2pCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;

namespace Solid.Identity.Protocols.Saml2p.Cache
Expand All @@ -22,13 +23,13 @@ public Saml2pCache(IDistributedCache inner)
public Task CacheRequestAsync(string key, AuthnRequest request)
{
var json = JsonSerializer.SerializeToUtf8Bytes(request);
return _inner.SetAsync(key, json);
return _inner.SetAsync(key, json, CreateOptions());
}

public Task CacheStatusAsync(string key, Status status)
{
var json = JsonSerializer.SerializeToUtf8Bytes(status);
return _inner.SetAsync($"{key}_status", json);
return _inner.SetAsync($"{key}_status", json, CreateOptions());
}

public async Task<AuthnRequest> FetchRequestAsync(string key)
Expand All @@ -52,5 +53,14 @@ public async Task RemoveAsync(string key)
await _inner.RemoveAsync(key);
await _inner.RemoveAsync($"{key}_status");
}

private DistributedCacheEntryOptions CreateOptions()
{
return new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
};
}

}
}

0 comments on commit 50aa7ef

Please sign in to comment.