diff --git a/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs b/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs index 94e7f51..ad3e2ba 100644 --- a/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs +++ b/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs @@ -8,18 +8,18 @@ using IP2Region.Net.Internal.Abstractions; namespace IP2Region.Net.Internal; -class ContentCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath) +class ContentCacheStrategy : AbstractCacheStrategy { ReadOnlyMemory _cacheData = default; + public ContentCacheStrategy(string xdbPath) : base(xdbPath) + { + using var reader = base.GetXdbFileStream(); + _cacheData = base.GetData(0, (int)reader.Length); + } + public override ReadOnlyMemory GetData(int offset, int length) { - if (_cacheData.IsEmpty) - { - using var reader = base.GetXdbFileStream(); - _cacheData = base.GetData(0, (int)reader.Length); - } - return _cacheData.Slice(offset, length); } } diff --git a/binding/csharp/IP2Region.Net/Internal/VectorIndexCacheStrategy.cs b/binding/csharp/IP2Region.Net/Internal/VectorIndexCacheStrategy.cs index 4dea3fe..f34b1b2 100644 --- a/binding/csharp/IP2Region.Net/Internal/VectorIndexCacheStrategy.cs +++ b/binding/csharp/IP2Region.Net/Internal/VectorIndexCacheStrategy.cs @@ -8,16 +8,14 @@ using IP2Region.Net.Internal.Abstractions; namespace IP2Region.Net.Internal; -internal class VectorIndexCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath) +internal class VectorIndexCacheStrategy : AbstractCacheStrategy { ReadOnlyMemory _vectorCahe = default; - public override ReadOnlyMemory GetVectorIndexStartPos(int offset) + public VectorIndexCacheStrategy(string xdbPath) : base(xdbPath) { - if (_vectorCahe.IsEmpty) - { - _vectorCahe = base.GetData(256, 256 * 256 * 8); - } - return _vectorCahe.Slice(offset, 8); + _vectorCahe = base.GetData(256, 256 * 256 * 8); } + + public override ReadOnlyMemory GetVectorIndexStartPos(int offset) => _vectorCahe.Slice(offset, 8); }