Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CacheInvalidationService.cs
2using System.Linq;
3using System.Threading.Tasks;
4using CommunityToolkit.Mvvm.Messaging;
7
9{
10 [Singleton]
11 internal sealed class CacheInvalidationService : ICacheInvalidationService
12 {
13 private readonly IInternetCacheService cache;
14
15 public CacheInvalidationService() : this(ServiceRef.InternetCacheService) { }
16 public CacheInvalidationService(IInternetCacheService cache)
17 {
18 this.cache = cache;
19 }
20
21 public async Task<int> InvalidateByParentId(string parentId, string scope)
22 {
23 int n = await this.cache.RemoveByParentId(parentId).ConfigureAwait(false);
24 WeakReferenceMessenger.Default.Send(new CacheInvalidatedMessage(scope, parentId, null));
25 return n;
26 }
27
28 public async Task<int> InvalidateByKeys(IEnumerable<string> keys, string scope)
29 {
30 int count = 0;
31 foreach (string key in keys ?? Enumerable.Empty<string>())
32 {
33 if (await this.cache.Remove(new System.Uri(key)).ConfigureAwait(false))
34 count++;
35 }
36 WeakReferenceMessenger.Default.Send(new CacheInvalidatedMessage(scope, null, keys?.ToList()));
37 return count;
38 }
39 }
40}
41
Base class that references services in the app.
Definition: ServiceRef.cs:43
Defines operations for caching arbitrary internet-fetchable content.
Task< int > RemoveByParentId(string ParentId)
Removes all cached entries having the specified parent ID.