perf: 优化缓存策略
This commit is contained in:
parent
30fa54a83f
commit
6684d0a928
|
|
@ -8,18 +8,18 @@ using IP2Region.Net.Internal.Abstractions;
|
|||
|
||||
namespace IP2Region.Net.Internal;
|
||||
|
||||
class ContentCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath)
|
||||
class ContentCacheStrategy : AbstractCacheStrategy
|
||||
{
|
||||
ReadOnlyMemory<byte> _cacheData = default;
|
||||
|
||||
public override ReadOnlyMemory<byte> GetData(int offset, int length)
|
||||
{
|
||||
if (_cacheData.IsEmpty)
|
||||
public ContentCacheStrategy(string xdbPath) : base(xdbPath)
|
||||
{
|
||||
using var reader = base.GetXdbFileStream();
|
||||
_cacheData = base.GetData(0, (int)reader.Length);
|
||||
}
|
||||
|
||||
public override ReadOnlyMemory<byte> GetData(int offset, int length)
|
||||
{
|
||||
return _cacheData.Slice(offset, length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<byte> _vectorCahe = default;
|
||||
|
||||
public override ReadOnlyMemory<byte> GetVectorIndexStartPos(int offset)
|
||||
{
|
||||
if (_vectorCahe.IsEmpty)
|
||||
public VectorIndexCacheStrategy(string xdbPath) : base(xdbPath)
|
||||
{
|
||||
_vectorCahe = base.GetData(256, 256 * 256 * 8);
|
||||
}
|
||||
return _vectorCahe.Slice(offset, 8);
|
||||
}
|
||||
|
||||
public override ReadOnlyMemory<byte> GetVectorIndexStartPos(int offset) => _vectorCahe.Slice(offset, 8);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue