Skip to content

Commit a160188

Browse files
committed
Proper cache items removal
Since cache type in 7.0 is different from one in 6.0 cache items removal should be fixed - updated Bitfaster to 1.0.7 to get Keys collection - updated FastConcurrentLruCache.Clear() method - removed LruCache.GetKeysInternal()
1 parent a24c503 commit a160188

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

ChangeLog/7.0.4_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[main] Updated BitFaster.Caching package to version 1.0.7

Orm/Xtensive.Orm/Caching/FastConcurrentLruCache{TKey, TItem}.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2021 Xtensive LLC.
1+
// Copyright (C) 2021-2023 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44

@@ -26,6 +26,11 @@ public class FastConcurrentLruCache<TKey, TItem> :
2626
/// <inheritdoc/>
2727
public long MaxSize { get; private set; }
2828

29+
/// <summary>
30+
/// Gets keys of cached items
31+
/// </summary>
32+
public IEnumerable<TKey> Keys => realCache.Keys;
33+
2934
/// <inheritdoc/>
3035
public override bool TryGetItem(TKey key, bool markAsHit, out TItem item) => realCache.TryGet(key, out item);
3136

@@ -53,15 +58,12 @@ public override TItem Add(TItem item, bool replaceIfExists)
5358
public override void RemoveKey(TKey key, bool removeCompletely) => realCache.TryRemove(key);
5459

5560
/// <inheritdoc/>
56-
public override void Clear() =>
57-
//TODO: Change to imp.Clear() after updating BitFaster.Caching package to 1.0.4
58-
realCache = new FastConcurrentLru<TKey, TItem>((int) MaxSize);
61+
public override void Clear() => realCache.Clear();
5962

6063
/// <inheritdoc/>
6164
/// <exception cref="NotImplementedException"/>
6265
public override IEnumerator<TItem> GetEnumerator() => throw new NotImplementedException();
6366

64-
6567
/// <summary>
6668
/// Initializes new instance of this type.
6769
/// </summary>

Orm/Xtensive.Orm/Caching/LruCache{TKey, TItem}.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ protected virtual void Cleared() { }
189189

190190
#endregion
191191

192-
internal IEnumerable<TKey> GetKeysInternal()
193-
{
194-
foreach (KeyValuePair<TKey, TItem> cachedItem in deque)
195-
yield return cachedItem.Key;
196-
}
197-
198192

199193
// Constructors
200194

Orm/Xtensive.Orm/Orm/StorageNodeManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2014-2020 Xtensive LLC.
1+
// Copyright (C) 2014-2023 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
@@ -60,9 +60,9 @@ public bool RemoveNode([NotNull] string nodeId, bool clearQueryCache = false)
6060
var removeResult = handlers.StorageNodeRegistry.Remove(nodeId);
6161

6262
if (removeResult && clearQueryCache) {
63-
var queryCache = (Caching.LruCache<object, Pair<object, Linq.TranslatedQuery>>) handlers.Domain.QueryCache;
64-
foreach (var key in queryCache.GetKeysInternal().Where(k => k is Pair<object, string> p && p.Second == nodeId).ToChainedBuffer()) {
65-
queryCache.RemoveKey(key, true);
63+
var queryCache = (Caching.FastConcurrentLruCache<object, Pair<object, Linq.ParameterizedQuery>>) handlers.Domain.QueryCache;
64+
foreach (var key in queryCache.Keys.Where(k => k is (object _, string keyNodeId) && keyNodeId == nodeId).ToChainedBuffer()) {
65+
queryCache.RemoveKey(key);
6666
}
6767
}
6868
return removeResult;

Orm/Xtensive.Orm/Xtensive.Orm.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<IsPackable>true</IsPackable>
44
<DocumentationFile>$(OutputPath)$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
@@ -41,7 +41,7 @@
4141
</ItemGroup>
4242
<ItemGroup Label="Packages">
4343
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
44-
<PackageReference Include="BitFaster.Caching" Version="1.0.3" />
44+
<PackageReference Include="BitFaster.Caching" Version="1.0.7" />
4545
</ItemGroup>
4646
<ItemGroup Label="T4GeneratorsUpdaters">
4747
<None Update="Arithmetic\Internal\PrimitiveArithmetics.tt">

0 commit comments

Comments
 (0)