Skip to content

Commit efba0a5

Browse files
authored
Mark AfterAccess policy internal (#466)
1 parent ba6ddc0 commit efba0a5

File tree

2 files changed

+126
-126
lines changed

2 files changed

+126
-126
lines changed
Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.Runtime.CompilerServices;
4-
5-
namespace BitFaster.Caching.Lru
6-
{
7-
#if !NETCOREAPP3_0_OR_GREATER
8-
/// <summary>
9-
/// Implement an expire after access policy.
10-
/// </summary>
11-
/// <remarks>
12-
/// This class measures time using Stopwatch.GetTimestamp() with a resolution of ~1us.
13-
/// </remarks>
14-
public readonly struct AfterAccessLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
15-
{
16-
private readonly long timeToLive;
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.CompilerServices;
4+
5+
namespace BitFaster.Caching.Lru
6+
{
7+
#if !NETCOREAPP3_0_OR_GREATER
8+
/// <summary>
9+
/// Implement an expire after access policy.
10+
/// </summary>
11+
/// <remarks>
12+
/// This class measures time using Stopwatch.GetTimestamp() with a resolution of ~1us.
13+
/// </remarks>
14+
internal readonly struct AfterAccessLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
15+
{
16+
private readonly long timeToLive;
1717
private readonly Time time;
1818

19-
///<inheritdoc/>
20-
public TimeSpan TimeToLive => StopwatchTickConverter.FromTicks(timeToLive);
21-
22-
/// <summary>
23-
/// Initializes a new instance of the TLruLongTicksPolicy class with the specified time to live.
24-
/// </summary>
25-
/// <param name="timeToLive">The time to live.</param>
26-
public AfterAccessLongTicksPolicy(TimeSpan timeToLive)
27-
{
28-
this.timeToLive = StopwatchTickConverter.ToTicks(timeToLive);
29-
this.time = new Time();
30-
}
31-
32-
///<inheritdoc/>
33-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34-
public LongTickCountLruItem<K, V> CreateItem(K key, V value)
35-
{
36-
return new LongTickCountLruItem<K, V>(key, value, Stopwatch.GetTimestamp());
37-
}
38-
39-
///<inheritdoc/>
40-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
41-
public void Touch(LongTickCountLruItem<K, V> item)
42-
{
43-
item.TickCount = this.time.Last;
44-
item.WasAccessed = true;
45-
}
46-
47-
///<inheritdoc/>
48-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
49-
public void Update(LongTickCountLruItem<K, V> item)
50-
{
51-
item.TickCount = Stopwatch.GetTimestamp();
52-
}
53-
54-
///<inheritdoc/>
55-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56-
public bool ShouldDiscard(LongTickCountLruItem<K, V> item)
57-
{
58-
this.time.Last = Stopwatch.GetTimestamp();
59-
if (this.time.Last - item.TickCount > this.timeToLive)
60-
{
61-
return true;
62-
}
63-
64-
return false;
65-
}
66-
67-
///<inheritdoc/>
68-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
69-
public bool CanDiscard()
70-
{
71-
return true;
72-
}
73-
74-
///<inheritdoc/>
75-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
76-
public ItemDestination RouteHot(LongTickCountLruItem<K, V> item)
77-
{
78-
if (this.ShouldDiscard(item))
79-
{
80-
return ItemDestination.Remove;
81-
}
82-
83-
if (item.WasAccessed)
84-
{
85-
return ItemDestination.Warm;
86-
}
87-
88-
return ItemDestination.Cold;
89-
}
90-
91-
///<inheritdoc/>
92-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93-
public ItemDestination RouteWarm(LongTickCountLruItem<K, V> item)
94-
{
95-
if (this.ShouldDiscard(item))
96-
{
97-
return ItemDestination.Remove;
98-
}
99-
100-
if (item.WasAccessed)
101-
{
102-
return ItemDestination.Warm;
103-
}
104-
105-
return ItemDestination.Cold;
106-
}
107-
108-
///<inheritdoc/>
109-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
110-
public ItemDestination RouteCold(LongTickCountLruItem<K, V> item)
111-
{
112-
if (this.ShouldDiscard(item))
113-
{
114-
return ItemDestination.Remove;
115-
}
116-
117-
if (item.WasAccessed)
118-
{
119-
return ItemDestination.Warm;
120-
}
121-
122-
return ItemDestination.Remove;
123-
}
124-
125-
}
126-
#endif
127-
}
19+
///<inheritdoc/>
20+
public TimeSpan TimeToLive => StopwatchTickConverter.FromTicks(timeToLive);
21+
22+
/// <summary>
23+
/// Initializes a new instance of the TLruLongTicksPolicy class with the specified time to live.
24+
/// </summary>
25+
/// <param name="timeToLive">The time to live.</param>
26+
public AfterAccessLongTicksPolicy(TimeSpan timeToLive)
27+
{
28+
this.timeToLive = StopwatchTickConverter.ToTicks(timeToLive);
29+
this.time = new Time();
30+
}
31+
32+
///<inheritdoc/>
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34+
public LongTickCountLruItem<K, V> CreateItem(K key, V value)
35+
{
36+
return new LongTickCountLruItem<K, V>(key, value, Stopwatch.GetTimestamp());
37+
}
38+
39+
///<inheritdoc/>
40+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
41+
public void Touch(LongTickCountLruItem<K, V> item)
42+
{
43+
item.TickCount = this.time.Last;
44+
item.WasAccessed = true;
45+
}
46+
47+
///<inheritdoc/>
48+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
49+
public void Update(LongTickCountLruItem<K, V> item)
50+
{
51+
item.TickCount = Stopwatch.GetTimestamp();
52+
}
53+
54+
///<inheritdoc/>
55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56+
public bool ShouldDiscard(LongTickCountLruItem<K, V> item)
57+
{
58+
this.time.Last = Stopwatch.GetTimestamp();
59+
if (this.time.Last - item.TickCount > this.timeToLive)
60+
{
61+
return true;
62+
}
63+
64+
return false;
65+
}
66+
67+
///<inheritdoc/>
68+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
69+
public bool CanDiscard()
70+
{
71+
return true;
72+
}
73+
74+
///<inheritdoc/>
75+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
76+
public ItemDestination RouteHot(LongTickCountLruItem<K, V> item)
77+
{
78+
if (this.ShouldDiscard(item))
79+
{
80+
return ItemDestination.Remove;
81+
}
82+
83+
if (item.WasAccessed)
84+
{
85+
return ItemDestination.Warm;
86+
}
87+
88+
return ItemDestination.Cold;
89+
}
90+
91+
///<inheritdoc/>
92+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93+
public ItemDestination RouteWarm(LongTickCountLruItem<K, V> item)
94+
{
95+
if (this.ShouldDiscard(item))
96+
{
97+
return ItemDestination.Remove;
98+
}
99+
100+
if (item.WasAccessed)
101+
{
102+
return ItemDestination.Warm;
103+
}
104+
105+
return ItemDestination.Cold;
106+
}
107+
108+
///<inheritdoc/>
109+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
110+
public ItemDestination RouteCold(LongTickCountLruItem<K, V> item)
111+
{
112+
if (this.ShouldDiscard(item))
113+
{
114+
return ItemDestination.Remove;
115+
}
116+
117+
if (item.WasAccessed)
118+
{
119+
return ItemDestination.Warm;
120+
}
121+
122+
return ItemDestination.Remove;
123+
}
124+
125+
}
126+
#endif
127+
}

BitFaster.Caching/Lru/AfterReadTickCount64Policy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace BitFaster.Caching.Lru
1313
/// than both Stopwatch.GetTimestamp and DateTime.UtcNow. However, resolution is lower (typically
1414
/// between 10-16ms), vs 1us for Stopwatch.GetTimestamp.
1515
/// </remarks>
16-
public readonly struct AfterAccessLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
16+
internal readonly struct AfterAccessLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
1717
{
1818
private readonly long timeToLive;
1919
private readonly Time time;

0 commit comments

Comments
 (0)