forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCachePutBatch.cs
48 lines (43 loc) · 1.37 KB
/
CachePutBatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using NHibernate.Engine;
namespace NHibernate.Cache
{
/// <summary>
/// A batch for batching the <see cref="ICacheConcurrencyStrategy.Put"/> operation.
/// </summary>
internal partial class CachePutBatch : AbstractCacheBatch<CachePutData>
{
public CachePutBatch(ISessionImplementor session, ICacheConcurrencyStrategy cacheConcurrencyStrategy) : base(session, cacheConcurrencyStrategy)
{
}
protected override void Execute(CachePutData[] data)
{
var length = data.Length;
var keys = new CacheKey[length];
var values = new object[length];
var versions = new object[length];
var versionComparers = new IComparer[length];
var minimalPuts = new bool[length];
for (int i = 0; i < length; i++)
{
var item = data[i];
keys[i] = item.Key;
values[i] = item.Value;
versions[i] = item.Version;
versionComparers[i] = item.VersionComparer;
minimalPuts[i] = item.MinimalPut;
}
var factory = Session.Factory;
var cacheStrategy = CacheConcurrencyStrategy;
var puts = cacheStrategy.PutMany(keys, values, Session.Timestamp, versions, versionComparers, minimalPuts);
if (factory.Statistics.IsStatisticsEnabled && puts.Any(o => o))
{
factory.StatisticsImplementor.SecondLevelCachePut(cacheStrategy.RegionName);
}
}
}
}