```ts
export class LruCache<K, V> {
  private readonly capacity: number;
  private readonly cacheMap: Map<K, V>;
  private const queue: K[] = [];

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

  get(key: K): V | undefined {
    if (this.cacheMap.has(key)) {
      const value = this.cacheMap.get(key);
      // Move the key to the end of the queue
      const i = this.queue.indexOf(key);
      this.queue.splice(i, 1);
      this.queue.push(key);
      return value;
    }
    return undefined;
  }

  set(key: K, value: V): void {
    if (this.cacheMap.has(key)) {
      // Update the existing key
      this.get(key); // Move to front of queue
    } else if (this.cacheMap.size >= this.capacity) {
      // Evict the least recently used item
      const lruKey = this.queue.shift();
      if (lruKey !== undefined) {
        this.cacheMap.delete(lruKey);
      }
    }
    // Add new key-value pair
    this.cacheMap.set(key, value);
    this.queue.push(key);
  }

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