Reboot / Restart
When SQL Server is rebooted, or the service is stopped and restarted, any DMV data is lost.
The hard way, delete all query plans from cache:
-- Never execute this on your production server
or you can target specific plans:
Keeping a large number of cached plans can quickly fill the available memory, especially in systems that create lots of SQL queries that differ subtly (for example, having different environment settings), resulting in separate cached plans for each one.
SQL Server manages the size of the procedure cache by maintaining the age of the execution plans in the cache. If a stored procedure is not re-executed for a long time, the age field of the execution plan can come down to 0, and the plan can be removed from the cache when SQL Server observes a pressure on its memory.
Recompile all queries related to a specific table or view:
EXEC sp_recompile <tablename>
Delete all query plans associated with a stored procedure.
-- Manually mark a stored procedure for recompilation, so it will be recompiled next time it is executed.
EXEC sp_recompile <procname>
Or you can enforce a query recompilation each time, then add a query hint to the end of the query:
Add the WITH RECOMPILE option when a stored proc is created:
CREATE PROCEDURE <ProcedureName>
When statistics are updated
More details about when statistics change.
Setting configuration option
optimize for ad hoc workloads to 1, will store only query_hash into the cache and and on second execution (if it happens), the plan itself will be placed in cache.
Parametrize all queries like in case of simple parametrization
ALTER DATABASE <dbname> SET PARAMETRIZATION FORCED;