```ts
export class LruCache<K, V> {
  private _capacity: number;
  private _size: number = 0;
  private _map: Map<K, V>;
  private _queue: K[];
  private _evictionThreshold: K;

  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<K, V>();
    this._queue = [];
    this._evictionThreshold = this._queue[this._capacity - 1];
  }

  get(key: K): V | undefined {
    if (!this._map.has(key)) return undefined;
    this._moveToTail(key);
    return this._map.get(key)!;
  }

  set(key: K, value: V) {
    if (this._map.has(key)) {
      this._map.set(key, value);
      this._moveToTail(key);
    } else {
      this._map.set(key, value);
      this._queue.push(key);
      this._size++;
      if (this._size > this._capacity) {
        const evictedKey = this._queue.shift()!;
        this._map.delete(evictedKey);
      }
    }
  }

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

  private _moveToTail(key: K): void {
    if (!this._map.has(key)) return;

    const index = this._queue.indexOf(key);
    if (index !== -1) {
      this._queue.splice(index, 1);
      this._queue.push(key);
    }
  }
}
```