Skip to main content
Glama
cache.test.ts1.2 kB
import { describe, it, expect, beforeEach } from 'vitest'; import { Cache } from '../../../src/utils/cache'; describe('Cache', () => { let cache: Cache<string>; beforeEach(() => { cache = new Cache<string>(1); // 1 second TTL for testing }); it('should store and retrieve values', () => { cache.set('key1', 'value1'); expect(cache.get('key1')).toBe('value1'); }); it('should return undefined for non-existent keys', () => { expect(cache.get('nonexistent')).toBeUndefined(); }); it('should delete values', () => { cache.set('key1', 'value1'); expect(cache.delete('key1')).toBe(true); expect(cache.get('key1')).toBeUndefined(); }); it('should clear all values', () => { cache.set('key1', 'value1'); cache.set('key2', 'value2'); cache.clear(); expect(cache.get('key1')).toBeUndefined(); expect(cache.get('key2')).toBeUndefined(); }); it('should expire values after TTL', async () => { cache.set('key1', 'value1'); expect(cache.get('key1')).toBe('value1'); // Wait for TTL to expire await new Promise(resolve => setTimeout(resolve, 1100)); expect(cache.get('key1')).toBeUndefined(); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Blakeem/Navidrome-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server