Updated cache implementation (fixed tree/dag mixup)