Table of Contents

CacheValidator Class

Definition

Namespace
Cuemon.Data.Integrity
Assemblies
Cuemon.Data.Integrity.dll
Source
src/Cuemon.Data.Integrity/CacheValidator.cs

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

Name Description
CacheValidator(EntityInfo, Func<Hash>, EntityDataIntegrityMethod)

Initializes a new instance of the CacheValidator class.

Properties

Name Description
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.

Created

Gets 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.

Method

Gets an enumeration value of EntityDataIntegrityMethod indicating 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).

ReferencePoint

Gets a CacheValidator object that represents an Assembly reference point.

Validation

Gets an enumeration value of EntityDataIntegrityValidation indicating the strength of this instance.

Methods

Name Description
Clone()

Creates a shallow copy of the current CacheValidator object.

CombineWith(byte[])

Combines the additionalChecksum to the representation of this instance.

GetMostSignificant()

Gets the most significant (largest) value of either Created or Modified.

GetMostSignificant(params CacheValidator[])

Gets the most significant CacheValidator object from the most significant (largest) value of either Created or Modified in the specified sequence.