Fixed bug with cache invalidation in middleware. Closes #1461
version bump