Nebula
SharedCache

SharedCacheHost

Serves the orchestrator's ISharedCacheStore to workers (RemoteSharedCacheClient) over the orchestrator's HTTP server, beside PersistenceHost: GET /cache/{key}: the object as application/octet-stream with its SHA-256 in X-Nebula-Checksum;...

generated from the sources
public sealed class SharedCacheHost

Serves the orchestrator's ISharedCacheStore to workers (RemoteSharedCacheClient) over the orchestrator's HTTP server, beside PersistenceHost:

  • GET /cache/{key}: the object as application/octet-stream with its SHA-256 in X-Nebula-Checksum; 404 when there is none
  • PUT /cache/{key}: the object as the body, with its SHA-256 in X-Nebula-Checksum. 201 when it was stored, 200 when the key was already stored. 400 for a bad key, a missing or wrong checksum, or an empty body; 413 over the size limit

Requests carry the mesh token in X-Nebula-Token when the mesh has one. Unlike the persistence endpoints, a request is answered on the HTTP server's own thread and never waits for the orchestrator's main thread, so a worker that is filling a cold cache cannot hold up the control plane. To keep it from starving the control plane of the HTTP server's threads instead, at most MaxConcurrent requests run at once; the rest get 503 and the worker treats that as a miss.

Constructors

SharedCacheHost

public SharedCacheHost(ISharedCacheStore store, string token, int maxObjectBytes = SharedCacheKey.DefaultMaxObjectBytes, int maxConcurrent = 8, int expiryDays = SharedCacheKey.DefaultExpiryDays);
ParameterDescription
storeWhere objects are kept. Owned by the caller.
tokenThe mesh token requests must present; null or empty for none.
maxObjectBytesLargest object accepted, in bytes.
maxConcurrentMost requests served at once.
expiryDaysDays an object may go unread before a sweep removes it; 0 or less keeps everything.

Fields

Prefix

public const string Prefix = "/cache";

The path prefix the cache is served under.

ChecksumHeader

public const string ChecksumHeader = "X-Nebula-Checksum";

The header that carries an object's checksum in both directions.

SweepIntervalSeconds

public const float SweepIntervalSeconds = 3600f;

Seconds between sweeps that remove expired keys.

FirstSweepSeconds

public const float FirstSweepSeconds = 60f;

Seconds after start before the first sweep.

Properties

Store

public ISharedCacheStore Store { get; }

MaxObjectBytes

public int MaxObjectBytes { get; }

Largest object accepted, in bytes.

MaxConcurrent

public int MaxConcurrent { get; }

Most requests served at once.

ExpiryDays

public int ExpiryDays { get; }

Days an object may go unread before a sweep removes it; 0 or less keeps everything.

Stats

public SharedCacheStats Stats { get; }

What this host has served since it started.

Methods

TryHandle

public bool TryHandle(OrchestratorHttpServer.Request req, out OrchestratorHttpServer.Response response);

Handle req when it addresses the cache. False for any other request. Safe to call from several threads: it blocks only on the store.

Tick

public void Tick(double nowSeconds);

Main thread, every frame: start a sweep when one is due. The sweep runs on the thread pool, first FirstSweepSeconds after the first call and then every SweepIntervalSeconds.

Sweep

public int Sweep();

Remove every object that has not been read for ExpiryDays days. Returns how many were removed. Called by Tick; call it directly to sweep at once.

Clear

public int Clear();

Remove every object (the dashboard's and the dev reset's way to start over). Persisted entities are not touched.

Describe

public string Describe();

The cache's size, as the dashboard and the status line report it.

On this page