Skip to main content

ServerCacheManager

A class in Root.Township, the global namespace.

Server version of CacheManager: loads or generates cache files in the server's cache folder, and asks clients to confirm they have downloaded a cache.

Constructors​

MemberWhat it is
ServerCacheManager()Creates a ServerCacheManager with default values.

Fields​

4 private and internal fields
MemberWhat it is
private Dictionary<string, Task> generatingCaches being generated right now, by name.
private static Logger loggerNLog logger for this class.
private Dictionary<Connection, Queue<ValueTuple<string, uint>>> requestedFilesQueue of requested files per connection. Not used in this code.
private Dictionary<Connection, Dictionary<string, TaskCompletionSource<bool>>> serverChecksPending cache download checks per connection and cache name.

Methods​

MemberWhat it is
override async Task CleanCache(string name)Waits for any generation of the cache to finish, then deletes the file.
async Task EnsureDownloadedToClient(Connection connection, string cache)Sends a FileCacheRequest for a cache file to a client and waits for its answer. Throws if the client fails.
override async Task<T> GetCache<T>(string name, Func<Task<T>> generate, Func<T> createEmpty)Reads a cache file if it exists; otherwise generates it, writes it to disk and returns it. Waits if it's already generating.
override void HandleCacheRequest(Connection connection, Stream stream)Reads a client's reply to a cache request and completes the matching pending check.
1 private and internal method
MemberWhat it is
private void Disconnected(Connection connection)When a client disconnects, fails all its pending cache checks.