Merge pull request #413 from 4ba-Co/fix/412-peak-memory-usage
fix: Correct abnormal memory spikes
This commit is contained in:
commit
fe2dfc1088
|
|
@ -3,25 +3,32 @@
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
// @Author Alan <lzh.shap@gmail.com>
|
// @Author Alan <lzh.shap@gmail.com>
|
||||||
// @Date 2023/07/25
|
// @Date 2023/07/25
|
||||||
// Updated by Argo Zhang <argo@live.ca> at 2025/11/21
|
// Updated by Wong <vcd.hai@outlook.com> at 2025/12/31
|
||||||
|
|
||||||
namespace IP2Region.Net.Internal;
|
namespace IP2Region.Net.Internal;
|
||||||
|
|
||||||
class ContentCacheStrategy : FileCacheStrategy
|
class ContentCacheStrategy(string xdbPath) : ICacheStrategy
|
||||||
{
|
{
|
||||||
private readonly ReadOnlyMemory<byte> _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<byte> _cacheData = File.ReadAllBytes(xdbPath);
|
||||||
|
|
||||||
|
public int IoCount => 0;
|
||||||
|
|
||||||
|
public void ResetIoCount()
|
||||||
{
|
{
|
||||||
_cacheData = base.GetData(0, (int)XdbFileStream.Length);
|
// Do nothing
|
||||||
XdbFileStream.Close();
|
|
||||||
XdbFileStream.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ReadOnlyMemory<byte> GetData(long offset, int length) => _cacheData.Slice((int)offset, length);
|
public ReadOnlyMemory<byte> GetVectorIndex(int offset)
|
||||||
|
=> _cacheData.Slice(HeaderInfoLength + offset, VectorIndexSize);
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
public ReadOnlyMemory<byte> GetData(long offset, int length) => _cacheData.Slice((int)offset, length);
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
{
|
{
|
||||||
base.Dispose(false);
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue