Class CacheValidator
Provides a way to represent cacheable data-centric content that can be validated by cache-aware applications.
public class CacheValidator : ChecksumBuilder, IEquatable<ChecksumBuilder>, IEntityInfo, IEntityDataTimestamp, IEntityDataIntegrity, IDataIntegrity
- Inheritance
-
CacheValidator
- Implements
- Inherited Members
Examples
The following example demonstrates how to create a CacheValidator to represent cacheable data with integrity validation, combining timestamps and content checksums.
using System;
using Cuemon.Data.Integrity;
using Cuemon.Security;
namespace MyApp.Examples;
public class Example
{
public void Run()
{
var entity = new EntityInfo(
DateTime.UtcNow.AddHours(-2),
DateTime.UtcNow.AddMinutes(-30)
);
var validator = new CacheValidator(entity, () => HashFactory.CreateFnv128(), EntityDataIntegrityMethod.Combined);
Console.WriteLine($"Created (UTC): {validator.Created:O}");
Console.WriteLine($"Modified (UTC): {validator.Modified:O}");
Console.WriteLine($"Validation: {validator.Validation}");
Console.WriteLine($"Method: {validator.Method}");
Console.WriteLine($"Checksum: {validator.Checksum.ToHexadecimalString()}");
// Combine with additional data
validator.CombineWith(BitConverter.GetBytes(67890L));
Console.WriteLine($"Combined: {validator}");
// Get the most significant from a sequence
var v1 = new CacheValidator(new EntityInfo(new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)), () => HashFactory.CreateFnv128());
var v2 = new CacheValidator(new EntityInfo(DateTime.UtcNow.AddDays(-1)), () => HashFactory.CreateFnv128());
var mostSignificant = CacheValidator.GetMostSignificant(v1, v2);
Console.WriteLine($"Most significant created: {mostSignificant.Created:O}");
// Use assembly reference point
CacheValidator.AssemblyReference = typeof(CacheValidator).Assembly;
var referencePoint = CacheValidator.ReferencePoint;
Console.WriteLine($"Reference point: {referencePoint}");
}
}
Constructors
CacheValidator(EntityInfo, Func<Hash>, EntityDataIntegrityMethod)
Initializes a new instance of the CacheValidator class.
public CacheValidator(EntityInfo entity, Func<Hash> hashFactory, EntityDataIntegrityMethod method = EntityDataIntegrityMethod.Unaltered)
Parameters
entityEntityInfoAn EntityInfo object that representing the meta-data of an entity.
hashFactoryFunc<Hash>The function delegate that is invoked to produce the HashResult.
methodEntityDataIntegrityMethodA EntityDataIntegrityMethod enumeration value that indicates how a checksum is manipulated. Default is Unaltered.
Exceptions
- InvalidEnumArgumentException
method
Properties
AssemblyReference
Gets or sets the Assembly that will serve as the ideal candidate for a CacheValidator reference point. Default is GetEntryAssembly() with a fallback to Cuemon.Core.dll.
public static Assembly AssemblyReference { get; set; }
Property Value
- Assembly
The assembly to use as a CacheValidator reference point.
Exceptions
- ArgumentNullException
valueis null.
Created
Gets a DateTime value from when data this instance represents was first created, expressed as the Coordinated Universal Time (UTC).
public DateTime Created { get; }
Property Value
- DateTime
A DateTime value from when data this instance represents was first created, expressed as the Coordinated Universal Time (UTC).
Default
Gets a CacheValidator object that is initialized to a default representation that should be considered invalid for usage beyond this check.
public static CacheValidator Default { get; }
Property Value
- CacheValidator
A CacheValidator object that is initialized to a default representation.
Method
Gets an enumeration value of EntityDataIntegrityMethod indicating the usage method of this instance.
public EntityDataIntegrityMethod Method { get; }
Property Value
- EntityDataIntegrityMethod
One of the enumeration values of EntityDataIntegrityMethod that indicates the usage method of this instance.
Modified
Gets a DateTime value from when data this instance represents was last modified, expressed as the Coordinated Universal Time (UTC).
public DateTime? Modified { get; }
Property Value
- DateTime?
A DateTime value from when data this instance represents was last modified, expressed as the Coordinated Universal Time (UTC).
ReferencePoint
Gets a CacheValidator object that represents an Assembly reference point.
public static CacheValidator ReferencePoint { get; }
Property Value
- CacheValidator
A CacheValidator object that represents an Assembly reference point.
Validation
Gets an enumeration value of EntityDataIntegrityValidation indicating the strength of this instance.
public EntityDataIntegrityValidation Validation { get; }
Property Value
- EntityDataIntegrityValidation
One of the enumeration values of EntityDataIntegrityValidation that specifies the strength of this instance.
Methods
Clone()
Creates a shallow copy of the current CacheValidator object.
public virtual CacheValidator Clone()
Returns
- CacheValidator
A new CacheValidator that is a copy of this instance.
CombineWith(byte[])
Combines the additionalChecksum to the representation of this instance.
public override ChecksumBuilder CombineWith(byte[] additionalChecksum)
Parameters
additionalChecksumbyte[]A byte[] containing a checksum of the additional data this instance must represent.
Returns
- ChecksumBuilder
A reference to this instance after the operation has completed.
GetMostSignificant()
public DateTime GetMostSignificant()
Returns
GetMostSignificant(params CacheValidator[])
Gets the most significant CacheValidator object from the most significant (largest) value of either Created or Modified in the specified sequence.
public static CacheValidator GetMostSignificant(params CacheValidator[] sequence)
Parameters
sequenceCacheValidator[]A sequence of CacheValidator objects to parse for the most significant (largest) value of either Created or Modified.
Returns
- CacheValidator
The most significant CacheValidator object from the specified
sequence.