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 AspectCache

From Leeroopedia
Revision as of 14:41, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Datahub_project_Datahub_AspectCache.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

Description

AspectCache is a simple TTL-based, thread-safe cache for entity aspects fetched from the DataHub server. It stores RecordTemplate aspect instances and automatically expires them after a configurable time-to-live (TTL) period. Expired aspects are lazily evicted on the next access attempt. The cache is backed by a ConcurrentHashMap for safe concurrent access from multiple threads.

This cache is the primary caching mechanism used by the Java SDK V2 entity layer to avoid redundant server fetches for recently accessed aspects.

Usage

AspectCache is used internally by entity objects to cache aspects retrieved from DataHub. Callers create an instance with a desired TTL in milliseconds, then use put() to store aspects and get() to retrieve them. Expired entries are transparently removed during retrieval.

Code Reference

Source Location

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

Signature

public class AspectCache {

    public AspectCache(long ttlMillis)

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

    public void put(@Nonnull String aspectName, @Nonnull RecordTemplate aspect)

    @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.AspectCache;

I/O Contract

Inputs

Method Parameter Type Description
constructor ttlMillis long Time-to-live in milliseconds for cached aspects
get aspectName String The name of the aspect to retrieve
get aspectClass Class<T> The expected class of the aspect
put aspectName String The name of the aspect to store
put aspect RecordTemplate The aspect data to cache
remove aspectName String The name of the aspect to remove

Outputs

Method Return Type Description
get T (nullable) The cached aspect cast to the requested type, or null if not found or expired
put void Stores the aspect with current timestamp
remove RecordTemplate (nullable) The removed aspect data, or null if not present
getAllAspects Map<String, RecordTemplate> All cached aspects (including expired ones)
isEmpty boolean Whether the cache is empty
size int Number of cached aspects

Usage Examples

// Create a cache with a 60-second TTL
AspectCache cache = new AspectCache(60_000L);

// Store an aspect
cache.put("ownership", ownershipAspect);

// Retrieve an aspect (returns null if expired or absent)
Ownership ownership = cache.get("ownership", Ownership.class);

// Remove a specific aspect
cache.remove("ownership");

// Check cache state
boolean empty = cache.isEmpty();
int count = cache.size();

// Get all cached aspects (snapshot)
Map<String, RecordTemplate> all = cache.getAllAspects();

Related Pages

Page Connections

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