2023-08-03 16:17:34 -07:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
public class CacheItem<T>
|
|
|
|
{
|
|
|
|
public ulong TimeToLiveTimestamp { get; set; }
|
|
|
|
|
|
|
|
public T Value { get; set; }
|
|
|
|
|
|
|
|
public bool HasExpired(ulong ttl)
|
|
|
|
{
|
2023-08-17 01:05:21 -07:00
|
|
|
// this specific value indicates the item is manually staled
|
|
|
|
if (TimeToLiveTimestamp == ulong.MaxValue)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-03 16:17:34 -07:00
|
|
|
return Time.GetTicksMsec() > TimeToLiveTimestamp + ttl;
|
|
|
|
}
|
2023-08-17 01:05:21 -07:00
|
|
|
|
|
|
|
public void Stale()
|
|
|
|
{
|
|
|
|
TimeToLiveTimestamp = ulong.MaxValue;
|
|
|
|
}
|
2023-08-03 16:17:34 -07:00
|
|
|
}
|