```ts
class LruCache<K, V> {
  private readonly capacity: number;
  private readonly cache: Map<K, { value: V; timestamp: number }>;
  private timestamp: number;

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

  get(key: K): V | undefined {
    const entry = this.cache.get(key);
    if (entry) {
      entry.timestamp = ++this.timestamp;
      return entry.value;
    }
    return undefined;
  }

  set(key: K, value: V): void {
    if (this.cache.size >= this.capacity) {
      const oldestEntry = Array.from(this.cache.entries()).reduce(
        (oldest, [_, entry]) => (entry.timestamp < oldest[1].timestamp ? [key, entry] : oldest),
        [null as unknown as K, { value: null as V, timestamp: 0 }]
      );
      this.cache.delete(oldestEntry[0]);
    }
    this.cache.set(key, { value, timestamp: ++this.timestamp });
  }

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