Class StoreCache
- Namespace
- McServerLauncher.Services
- Assembly
- McServerLauncher.dll
Two-level cache (memory, then disk, then the network) for the store's API responses. It exists so that opening a mod — and going back and opening it again — costs one request, not one per visit, and so that a project already seen still opens with no connection.
Concurrent callers asking for the same key share a single fetch: opening a details page kicks off the project, its versions and its dependencies at once, and the related-mods strip may ask for a project that is already in flight.
Entries are kept on disk beyond their freshness window on purpose: when the network fails, a stale entry is a much better answer than an empty page. Anything older than McServerLauncher.Services.StoreCache.MaxDiskAge is pruned once per run.
public sealed class StoreCache
- Inheritance
-
StoreCache
- Inherited Members
Constructors
StoreCache(string?)
public StoreCache(string? cacheDir = null)
Parameters
cacheDirstring
Fields
Shared
Shared instance: the cache is only useful if every view model hits the same one.
public static readonly StoreCache Shared
Field Value
Methods
GetOrFetchAsync<T>(string, TimeSpan, Func<CancellationToken, Task<T?>>, CancellationToken)
Returns the cached value when it is younger than ttl, otherwise calls
fetch and stores the result. A failed or empty fetch falls back to a
stale copy when there is one, so the UI degrades to "slightly old" instead of "nothing".
public Task<T?> GetOrFetchAsync<T>(string key, TimeSpan ttl, Func<CancellationToken, Task<T?>> fetch, CancellationToken ct = default) where T : class
Parameters
keystringttlTimeSpanfetchFunc<CancellationToken, Task<T>>ctCancellationToken
Returns
- Task<T>
Type Parameters
T
Invalidate(string)
Drops a key from memory so the next read goes back to the network.
public void Invalidate(string key)
Parameters
keystring