Skip to main content

GraphManager

Application-scoped singleton for cache initialization and management.

Import

import { GraphManager } from 'grafio';

init()

static init(config: GraphManagerConfig): void

Initialize the GraphManager with cache configuration.

GraphManagerConfig

interface GraphManagerConfig {
cache?: CacheConfig;
}

Example

import { GraphManager, InMemoryStorageProvider } from 'grafio';

GraphManager.init({
cache: {
maxNodesCount: 10000,
maxEdgesCount: 20000,
cacheStore: 'in-memory',
evictionStrategy: 'LRU',
preloadStrategy: 'none',
}
});

// Graph instances created via factory use caching automatically when enabled
const factory = new InMemoryGraphFactory();
const graph = factory.forGraph();

getCacheManager()

static getCacheManager(): CacheManager | undefined

Returns the CacheManager instance if initialized with cache config.

const cacheManager = GraphManager.getCacheManager();
if (cacheManager) {
const stats = cacheManager.getStats('default');
}

reset()

static reset(): void

Reset the GraphManager singleton. Mainly for testing.

GraphManager.reset();
GraphManager.init({ /* new config */ });

Next Steps