Got rid of the casting problem not through generics, but by accessing `cachedState` only once per proxy handler.