```typescript
/**
 * A fixed-capacity least-recently-used cache.
 */
export class LruCache<K, V> {
    private capacity: number;
    private map: Map<K, { value: V; index: number }>;
    private list: K[] = [];
    private size: number;

    /**
     * Creates a new LruCache instance.
     *
     * @param capacity The maximum number of entries in the cache.
     */
    constructor(capacity: number) {
        if (typeof capacity !== 'number' || capacity <= 0) {
            throw new Error('Capacity must be a positive integer.');
        }
        this.capacity = capacity;
        this.map = new Map();
        this.size = 0;
    }

    /**
     * Returns the value associated with the given key, or undefined if no such entry exists.
     *
     * @param key The key to look up in the cache.
     */
    get(key: K): V | undefined {
        const entry = this.map.get(key);
        if (entry) {
            this.list.splice(this.list.indexOf(key), 1);
            this.list.push(key);
            return entry.value;
        }
        return undefined;
    }

    /**
     * Inserts or updates the value associated with the given key in the cache.
     *
     * @param key The key to insert or update in the cache.
     * @param value The new value to associate with the key.
     */
    set(key: K, value: V): void {
        const entry = this.map.get(key);
        if (entry) {
            entry.value = value;
            this.list.splice(this.list.indexOf(key), 1);
            this.list.push(key);
        } else {
            if (this.size >= this.capacity) {
                const lruKey = this.list.pop();
                this.map.delete(lruKey);
            }
            this.map.set(key, { value, index: this.list.length });
            this.list.push(key);
        }
        this.size++;
    }

    /**
     * Returns the number of entries currently in the cache.
     *
     * @returns The current size of the cache.
     */
    get size(): number {
        return this.size;
    }
}
```