diff --git a/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs b/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs index 020a959..2e980b7 100644 --- a/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs +++ b/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs @@ -3,25 +3,32 @@ // license that can be found in the LICENSE file. // @Author Alan // @Date 2023/07/25 -// Updated by Argo Zhang at 2025/11/21 +// Updated by Wong at 2025/12/31 namespace IP2Region.Net.Internal; -class ContentCacheStrategy : FileCacheStrategy +class ContentCacheStrategy(string xdbPath) : ICacheStrategy { - private readonly ReadOnlyMemory _cacheData; + // TODO: these constants can be moved to the interface as defaults when using .NET 10 + private const int HeaderInfoLength = 256; + private const int VectorIndexSize = 8; - public ContentCacheStrategy(string xdbPath) : base(xdbPath) + private readonly ReadOnlyMemory _cacheData = File.ReadAllBytes(xdbPath); + + public int IoCount => 0; + + public void ResetIoCount() { - _cacheData = base.GetData(0, (int)XdbFileStream.Length); - XdbFileStream.Close(); - XdbFileStream.Dispose(); + // Do nothing } - public override ReadOnlyMemory GetData(long offset, int length) => _cacheData.Slice((int)offset, length); + public ReadOnlyMemory GetVectorIndex(int offset) + => _cacheData.Slice(HeaderInfoLength + offset, VectorIndexSize); - protected override void Dispose(bool disposing) + public ReadOnlyMemory GetData(long offset, int length) => _cacheData.Slice((int)offset, length); + + public void Dispose() { - base.Dispose(false); + // Do nothing } }