Adding to the cache if caching is needed