Why not have a utility function that both places call? I think you really want to have the thing that's creating things in the cache and the thing that's removing things from the cache to be using the same code to compose keys.