Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions Orm/Xtensive.Orm/Orm/StorageNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
// Created by: Denis Krjuchkov
// Created: 2014.03.13

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Lru;
using Xtensive.Core;
using Xtensive.Orm.Configuration;
using Xtensive.Orm.Interfaces;
Expand All @@ -26,6 +22,8 @@ namespace Xtensive.Orm
/// </summary>
public sealed class StorageNode : ISessionSource
{
private const int CacheCapacity = 256;

private readonly Domain domain;

/// <summary>
Expand All @@ -51,29 +49,29 @@ public sealed class StorageNode : ISessionSource
/// <summary>
/// Caches providers that lock certain type of entity with certain <see cref="LockMode"/> and <see cref="LockBehavior"/>.
/// </summary>
internal ConcurrentDictionary<(TypeInfo, LockMode, LockBehavior), ExecutableProvider> EntityLockProviderCache { get; } = new();
internal FastConcurrentLru<(TypeInfo, LockMode, LockBehavior), ExecutableProvider> EntityLockProviderCache { get; } = new(CacheCapacity);

/// <summary>
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch certain entities.
/// </summary>
internal ConcurrentDictionary<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new();
internal FastConcurrentLru<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new(CacheCapacity);

/// <summary>
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch <see cref="EntitySet{TItem}"/> content.
/// </summary>
internal ConcurrentDictionary<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new();
internal FastConcurrentLru<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new(CacheCapacity);

/// <summary>
/// Caches certain info about EntitySet fields, e.g. queries to fetch current count or items.
/// </summary>
internal ConcurrentDictionary<Xtensive.Orm.Model.FieldInfo, EntitySetTypeState> EntitySetTypeStateCache { get; } = new();
internal FastConcurrentLru<Xtensive.Orm.Model.FieldInfo, EntitySetTypeState> EntitySetTypeStateCache { get; } = new(CacheCapacity);

/// <summary>
/// Caches queries that get references to entities for certain association.
/// </summary>
internal ConcurrentDictionary<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new();
internal ConcurrentDictionary<SequenceInfo, CachingSequence> KeySequencesCache { get; } = new();
internal ConcurrentDictionary<PersistRequestBuilderTask, IReadOnlyList<PreparedPersistRequest>> PersistRequestCache { get; } = new();
internal FastConcurrentLru<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new(CacheCapacity);
internal FastConcurrentLru<SequenceInfo, CachingSequence> KeySequencesCache { get; } = new(CacheCapacity);
internal FastConcurrentLru<PersistRequestBuilderTask, IReadOnlyList<PreparedPersistRequest>> PersistRequestCache { get; } = new(CacheCapacity);

/// <inheritdoc/>
public Session OpenSession() =>
Expand Down Expand Up @@ -115,8 +113,8 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel

public void ClearSequenceCaches()
{
foreach (var seq in KeySequencesCache.Values) {
seq.Reset();
foreach (var (_, v) in KeySequencesCache) {
v.Reset();
}
}

Expand Down