```typescript
export class LruCache<K, V> {
  private capacity: number;
  private cache: Map<K, [V, number]>;
  private order: K[];

  /**
   * Creates a new LruCache with the given capacity.
   *
   * @param capacity The maximum number of items to store in the cache.
   */
  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();
    this.order = [];
  }

  /**
   * Returns the value associated with the given key, or undefined if no such key exists.
   *
   * @param key The key to look up in the cache.
   */
  get(key: K): V | undefined {
    const [value, index] = this.cache.get(key) || [undefined, -1];

    if (value !== undefined) {
      const oldIndex = this.order.indexOf(key);
      this.order.splice(oldIndex, 1);

      // Add the key back to the end of the order array
      this.order.push(key);
      this.cache.set(key, [value, this.order.length - 1]);
      return value;
    }

    // Get the current size of the cache
    const size = this.size;

    // If the cache is full and a get operation is performed, remove the least recently used item
    if (size === this.capacity && !this.cache.has(key)) {
      const oldestKey = this.order.shift() as K;
      delete this.cache.get(oldestKey);
      this.cache.delete(oldestKey);
    }

    return undefined;
  }

  /**
   * Inserts or updates the given key with the given value in the cache.
   *
   * @param key The key to insert or update in the cache.
   * @param value The value to associate with the given key.
   */
  set(key: K, value: V): void {
    if (this.cache.has(key)) {
      this.cache.get(key)[0] = value;
      const index = this.order.indexOf(key);
      this.order.splice(index, 1);
      this.order.push(key);
      return;
    }

    if (this.capacity === 0) {
      throw new Error('Cache is full');
    }

    this.cache.set(key, [value, this.order.length]);
    this.order.push(key);
  }

  /**
   * Returns the current size of the cache.
   *
   * @returns The number of items currently in the cache.
   */
  get size(): number {
    return this.cache.size;
  }
}
```