Refactor cache mechanism

Extract one cache mechanism.
Cache was duplicated in positionUtils and gridPositionCache.