```typescript
export class LruCache<K, V> {
    private readonly capacity: number;
    private readonly cache: Map<K, V>;
    private readonly usageQueue: K[];

    constructor(capacity: number) {
        if (capacity <= 0 || !Number.isInteger(capacity)) {
            throw new Error("Capacity must be a positive integer");
        }
        this.capacity = capacity;
        this.cache = new Map();
        this.usageQueue = [];
    }

    get(key: K): V | undefined {
        if (!this.cache.has(key)) {
            return undefined;
        }
        this.usageQueue = this.usageQueue.filter(k => k !== key);
        this.usageQueue.push(key);
        return this.cache.get(key)!;
    }

    set(key: K, value: V): void {
        if (this.cache.size >= this.capacity) {
            const lruKey = this.usageQueue.shift();
            if (lruKey) {
                this.cache.delete(lruKey);
            }
        }
        this.cache.set(key, value);
        this.usageQueue.push(key);
    }

    get size(): number {
        return this.cache.size;
    }
}
```