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

    /**
     * Creates a new LruCache with the given capacity.
     *
     * @param capacity The maximum number of entries in the cache.
     */
    constructor(capacity: number) {
        if (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 [value, index] = this.map.get(key);
        if (value === undefined) return undefined;
        this.list.splice(index, 1);
        this.list.push(key);
        return value;
    }

    /**
     * Inserts or updates the given key with the given value.
     *
     * @param key The key to insert or update in the cache.
     * @param value The value associated with the key.
     */
    set(key: K, value: V): void {
        if (this.map.has(key)) {
            this.list.splice(this.list.indexOf(key), 1);
        }
        const index = this.list.length;
        this.list.push(key);
        this.size++;
        if (index >= this.capacity) {
            const removedKey = this.list.shift() as K;
            this.map.delete(removedKey);
            this.size--;
        }
        this.map.set(key, [value, index]);
    }

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