```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 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.size++;
            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 {
        if (this.map.has(key)) {
            this.size++;
            const entry = this.map.get(key);
            entry.value = value;
            entry.index = this.size - 1;
        } else {
            this.size++;
            this.map.set(key, { value, index: this.size - 1 });
            if (this.size > this.capacity) {
                const oldestEntry = this.map.keys().next().value;
                this.map.delete(oldestEntry);
                this.size--;
            }
        }
    }

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