Fixes #4978 clears db query cache when it reaches 500 queries