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

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

  private evictLeastRecentlyUsed() {
    const entries = Array.from(this.cache.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp);
    this.cache.delete(entries[0][0]);
  }

  public set(key: K, value: V): void {
    if (this.cache.has(key)) {
      this.cache.set(key, { value, timestamp: Date.now() });
    } else {
      this.cache.set(key, { value, timestamp: Date.now() });
      if (this.cache.size > this.capacity) {
        this.evictLeastRecentlyUsed();
      }
    }
  }

  public get(key: K): V | undefined {
    if (!this.cache.has(key)) return;

    const entry = this.cache.get(key);
    this.cache.set(key, { value: entry.value, timestamp: Date.now() });
    return entry.value;
  }

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