Table of Contents

Class PathCache

Namespace
Core.Systems
Assembly
Core.dll

ENGINE: LRU cache for pathfinding results.

Caches computed paths to avoid redundant A* searches. Uses simple LRU eviction when cache is full.

Cache key: (start, goal) pair Cache invalidation: Manual clear or frame-based expiry

Thread safety: NOT thread-safe (single-threaded pathfinding assumed)

public class PathCache
Inheritance
object
PathCache

Constructors

PathCache(int)

Create a path cache with specified maximum size.

public PathCache(int maxSize = 256)

Parameters

maxSize int

Maximum number of cached paths

Properties

Count

Number of cached paths

public int Count { get; }

Property Value

int

HitCount

Cache hit count since last reset

public int HitCount { get; }

Property Value

int

HitRate

Cache hit rate (0-1)

public float HitRate { get; }

Property Value

float

MaxSize

Maximum cache size

public int MaxSize { get; }

Property Value

int

MissCount

Cache miss count since last reset

public int MissCount { get; }

Property Value

int

Methods

Add(ushort, ushort, List<ushort>, FixedPoint64)

Add a path to the cache.

public void Add(ushort start, ushort goal, List<ushort> path, FixedPoint64 cost)

Parameters

start ushort
goal ushort
path List<ushort>
cost FixedPoint64

Clear()

Clear all cached paths.

public void Clear()

GetStats()

Get cache statistics as string.

public string GetStats()

Returns

string

InvalidateEndpoint(ushort)

Invalidate all paths for a specific start or goal province.

public void InvalidateEndpoint(ushort provinceId)

Parameters

provinceId ushort

InvalidateProvince(ushort)

Invalidate paths that pass through a specific province. Call when a province becomes blocked/unblocked.

public void InvalidateProvince(ushort provinceId)

Parameters

provinceId ushort

ResetStats()

Reset statistics.

public void ResetStats()

TryGet(ushort, ushort, out List<ushort>, out FixedPoint64)

Try to get a cached path.

public bool TryGet(ushort start, ushort goal, out List<ushort> path, out FixedPoint64 cost)

Parameters

start ushort
goal ushort
path List<ushort>
cost FixedPoint64

Returns

bool