Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Datahub project Datahub WriteTrackingAspectCache

From Leeroopedia


Knowledge Sources
Domains Java_SDK, Metadata_Management
Last Updated 2026-02-10 00:00 GMT

Overview

Description

WriteTrackingAspectCache is an extended, thread-safe cache for entity aspects with TTL-based expiration and dirty tracking. It extends the caching concept of AspectCache by adding support for distinguishing between server-sourced and locally-sourced aspects, tracking dirty (unsaved) state, and controlling read visibility via ReadMode.

Note: This class is currently not in active use. It is preserved for future implementation of write tracking and read-your-own-writes semantics.

Key capabilities:

  • TTL-based expiration for SERVER-sourced aspects; LOCAL-sourced aspects never expire
  • Dirty tracking to identify aspects with pending writes
  • Read modes: ALLOW_DIRTY returns dirty aspects (read-your-own-writes), SERVER_ONLY filters them out
  • Thread-safe operations via ConcurrentHashMap

Usage

This cache would be used by entity objects to track both fetched and locally modified aspects. Callers use put() with an AspectSource and dirty flag, get() with a ReadMode, and markDirty() / markClean() to manage write state. After a successful server save, clearDirty() resets all dirty flags.

Code Reference

Source Location

metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/WriteTrackingAspectCache.java

Signature

public class WriteTrackingAspectCache {

    public WriteTrackingAspectCache(long ttlMillis)

    @Nullable
    public <T extends RecordTemplate> T get(
        @Nonnull String aspectName,
        @Nonnull Class<T> aspectClass,
        @Nonnull ReadMode readMode)

    public void put(
        @Nonnull String aspectName,
        @Nonnull RecordTemplate aspect,
        @Nonnull AspectSource source,
        boolean dirty)

    public void markDirty(@Nonnull String aspectName)

    @Nonnull
    public Map<String, RecordTemplate> getDirtyAspects()

    public boolean hasPendingWrites(@Nonnull String aspectName)

    public void markClean(@Nonnull String aspectName)

    public void clearDirty()

    @Nullable
    public RecordTemplate remove(@Nonnull String aspectName)

    @Nonnull
    public Map<String, RecordTemplate> getAllAspects()

    public boolean isEmpty()

    public int size()
}

Import

import datahub.client.v2.entity.WriteTrackingAspectCache;

I/O Contract

Inputs

Method Parameter Type Description
constructor ttlMillis long TTL in milliseconds for SERVER-sourced aspects
get aspectName String Name of the aspect to retrieve
get aspectClass Class<T> Expected class of the aspect
get readMode ReadMode ALLOW_DIRTY or SERVER_ONLY
put aspectName String Name of the aspect to store
put aspect RecordTemplate The aspect data to cache
put source AspectSource SERVER or LOCAL
put dirty boolean Whether the aspect has unsaved modifications
markDirty aspectName String Name of the aspect to mark dirty
markClean aspectName String Name of the aspect to mark clean
remove aspectName String Name of the aspect to remove

Outputs

Method Return Type Description
get T (nullable) Cached aspect or null if not found, expired, or filtered by read mode
getDirtyAspects Map<String, RecordTemplate> All aspects with unsaved modifications
hasPendingWrites boolean Whether the named aspect has pending writes
remove RecordTemplate (nullable) The removed aspect data or null
getAllAspects Map<String, RecordTemplate> All cached aspects (clean and dirty)
isEmpty boolean Whether the cache is empty
size int Number of cached aspects

Usage Examples

// Create a cache with 60-second TTL for server-sourced aspects
WriteTrackingAspectCache cache = new WriteTrackingAspectCache(60_000L);

// Store a server-sourced aspect (subject to TTL)
cache.put("ownership", ownershipAspect, AspectSource.SERVER, false);

// Store a locally modified aspect (never expires, starts dirty)
cache.put("description", descAspect, AspectSource.LOCAL, true);

// Read with different modes
Ownership ownership = cache.get("ownership", Ownership.class, ReadMode.ALLOW_DIRTY);
Ownership serverOnly = cache.get("ownership", Ownership.class, ReadMode.SERVER_ONLY);

// Check and manage dirty state
boolean pending = cache.hasPendingWrites("description");
cache.markClean("description");
cache.clearDirty();

// Get all dirty aspects for batch save
Map<String, RecordTemplate> dirtyAspects = cache.getDirtyAspects();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment