ip2region/binding/csharp/IP2Region.Net/Internal/ContentCacheStrategy.cs
2025-11-21 09:42:59 +08:00

26 lines
765 B
C#

// Copyright 2023 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file.
// @Author Alan <lzh.shap@gmail.com>
// @Date 2023/07/25
using IP2Region.Net.Internal.Abstractions;
namespace IP2Region.Net.Internal;
class ContentCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath)
{
ReadOnlyMemory<byte> _cacheData = ReadOnlyMemory<byte>.Empty;
internal override ReadOnlyMemory<byte> 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);
}
}