12 internal sealed
class AttachmentCacheService :
LoadableService, IAttachmentCacheService
14 private static readonly TimeSpan defaultExpiry = TimeSpan.FromHours(24);
15 private readonly FileCacheManager cacheManager;
20 public AttachmentCacheService()
22 this.cacheManager =
new FileCacheManager(
"Attachments", defaultExpiry);
26 public override async Task Load(
bool IsResuming, CancellationToken CancellationToken)
28 if (this.
BeginLoad(IsResuming, CancellationToken))
33 await this.cacheManager.EvictOldEntries();
46 public Task<(
byte[]? Data,
string ContentType)> TryGet(
string Url)
48 return this.cacheManager.TryGet(Url);
52 public Task Add(
string Url,
string ParentId,
bool Permanent,
byte[] Data,
string ContentType)
54 return this.cacheManager.AddOrUpdate(Url, ParentId, Permanent, Data, ContentType);
58 public Task<bool> Remove(
string Url)
60 return this.cacheManager.Remove(Url);
64 public async Task<bool> RemoveAttachments(
Attachment[]? Attachments)
66 if (Attachments is
null)
74 bool EntryRemoved = await this.cacheManager.Remove(
Attachment.
Url);
84 public Task MakeTemporary(
string ParentId)
86 return this.cacheManager.MakeTemporary(ParentId);
90 public Task MakePermanent(
string ParentId)
92 return this.cacheManager.MakePermanent(ParentId);
bool BeginLoad(bool IsResuming, CancellationToken CancellationToken)
Sets the IsLoading flag if the service isn't already loading.
void EndLoad(bool isLoaded)
Sets the IsLoading and IsLoaded flags and fires an event representing the current load state of the s...
bool IsResuming
If App is resuming service.
Contains a reference to an attachment assigned to a legal object.
string ContentType
Internet Content Type of binary attachment.
string Url
URL to retrieve attachment, if provided.