```python:inference/core/interfaces/camera/test_pattern_producer.py
from typing import Dict

import numpy as np

GRID_COLS = 16
GRID_ROWS = 9



# Module-level cache mapping seed -> read-only numpy array of generated colors.
_CACHE: Dict[int, np.ndarray] = {}


def _generate_grid_colors(seed: int) -> np.ndarray:
    rng = None
    # Fast path: return a copy of a cached array if available.
    cached = _CACHE.get(seed)
    if cached is not None:
        return cached.copy()

    # Slow path: create RandomState once for this seed, generate array, cache it as read-only,
    # and return a copy to preserve the original behavior of returning a new array each call.
    rng = np.random.RandomState(seed)
    arr = rng.randint(40, 220, size=(GRID_ROWS, GRID_COLS, 3), dtype=np.uint8)
    arr.setflags(write=False)
    _CACHE[seed] = arr
    return arr.copy()
```