NuCache: reorg some classes
This commit is contained in:
37
src/Umbraco.Web/PublishedCache/NuCache/Snap/GenObj.cs
Normal file
37
src/Umbraco.Web/PublishedCache/NuCache/Snap/GenObj.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.Snap
|
||||
{
|
||||
internal class GenObj
|
||||
{
|
||||
public GenObj(long gen)
|
||||
{
|
||||
Gen = gen;
|
||||
WeakGenRef = new WeakReference(null);
|
||||
}
|
||||
|
||||
public GenRef GetGenRef()
|
||||
{
|
||||
// not thread-safe but always invoked from within a lock
|
||||
var genRef = (GenRef)WeakGenRef.Target;
|
||||
if (genRef == null)
|
||||
WeakGenRef.Target = genRef = new GenRef(this);
|
||||
return genRef;
|
||||
}
|
||||
|
||||
public readonly long Gen;
|
||||
public readonly WeakReference WeakGenRef;
|
||||
public int Count;
|
||||
|
||||
public void Reference()
|
||||
{
|
||||
Interlocked.Increment(ref Count);
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
Interlocked.Decrement(ref Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/Umbraco.Web/PublishedCache/NuCache/Snap/GenRef.cs
Normal file
13
src/Umbraco.Web/PublishedCache/NuCache/Snap/GenRef.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.Snap
|
||||
{
|
||||
internal class GenRef
|
||||
{
|
||||
public GenRef(GenObj genObj)
|
||||
{
|
||||
GenObj = genObj;
|
||||
}
|
||||
|
||||
public readonly GenObj GenObj;
|
||||
public long Gen => GenObj.Gen;
|
||||
}
|
||||
}
|
||||
20
src/Umbraco.Web/PublishedCache/NuCache/Snap/LinkedNode.cs
Normal file
20
src/Umbraco.Web/PublishedCache/NuCache/Snap/LinkedNode.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.Snap
|
||||
{
|
||||
internal class LinkedNode<TValue>
|
||||
where TValue : class
|
||||
{
|
||||
public LinkedNode(TValue value, long gen, LinkedNode<TValue> next = null)
|
||||
{
|
||||
Value = value;
|
||||
Gen = gen;
|
||||
Next = next;
|
||||
}
|
||||
|
||||
public readonly long Gen;
|
||||
|
||||
// reading & writing references is thread-safe on all .NET platforms
|
||||
// mark as volatile to ensure we always read the correct value
|
||||
public volatile TValue Value;
|
||||
public volatile LinkedNode<TValue> Next;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user