Adhoc Queries filling up plan cache I have a bloated plan cache because of Adhoc queries. 
I have SQL job that goes in and purges Adhoc plans every hour. (This process was adopted from Kimberly Tripp in regards to Plan cache bloat). 
When I look at the top 50 adhoc plans I see this (with much more content in each row) for all 50:

Select '100', 0, ''; begin try dbcc inputbuffer(100) with no_infomsgs end try begin catch select 'RPC Event',0,'(unknown)' end catch; Select '102', 0, ''; 

How can I prevent that from filling up my plan cache? BTW..
I do have optimize for ad hoc workloads on.

Thanks,
Shelz
Following can be used to clean adhoc and prepared query plan cache . This is from Glenn Berry - Eight Different Ways to Clear the SQL Server Plan Cache

DBCC FREESYSTEMCACHE ('SQL Plans') 


It also says:


  “I would argue that running DBCC FREEPROCCACHE does not cause that much distress with a modern processor, even on a very busy OLTP system. It will cause a pretty minor CPU spike for a few seconds on most systems as the query plans get recompiled as they are executed. “


Following query can give adhoc queries in the plan cache

SELECT  DISTINCT 
        QCP.objtype
        ,MultipleQ.PlanCount
        ,qStat.query_hash
        ,sText.text AS QueryText
        ,size_in_bytes
        ,qStat.creation_time
FROM ( 
        SELECT query_hash,
               COUNT(query_hash) AS PlanCount
        FROM sys.dm_exec_query_stats
        GROUP BY query_hash
    ) AS MultipleQ
INNER JOIN sys.dm_exec_query_stats qStat ON MultipleQ.query_hash = qStat.query_hash
INNER JOIN sys.dm_exec_cached_plans  QCP
    ON QCP.plan_handle = qStat.plan_handle
CROSS APPLY sys.dm_exec_sql_text(qStat.sql_handle) AS sText
CROSS APPLY sys.dm_exec_query_plan(qStat.plan_handle) AS qp
WHERE PlanCount &gt; 1
AND QCP.objtype = 'Adhoc'
ORDER BY MultipleQ.PlanCount DESC


If you have Query Store you can use “Delete ad-hoc queries” as defined in 
Monitoring performance by using the Query Store

Enabling optimize for adhoc workloads can be found in  Kimberly Tripp - Plan cache and optimizing for adhoc workloads