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

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

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

  set(key: K, value: V): void {
    if (this.cache.has(key)) {
      this.cache.delete(key);
    } else if (this.cache.size >= this.capacity) {
      const oldestEntry = Array.from(this.cache).reduce((a, b) =>
        a[1].timestamp < b[1].timestamp ? a : b
      );
      this.cache.delete(oldestEntry[0]);
    }
    this.cache.set(key, { value, timestamp: this.timestamp++ });
  }

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

  private updateTimestamp(entry: { value: V; timestamp: number }): void {
    entry.timestamp = this.timestamp++;
  }
}
```