Script to purge TokenAndPermUserStore


 

Here is a script that purge the 'TokenAndPermUserStore' every time it reaches 100MB.


 


 


DECLARE @CacheSize int


DECLARE @CurDate varchar(30)


 


WHILE (1=1)


BEGIN


SET @CurDate = CONVERT (varchar, GETDATE(), 126)


SELECT @CacheSize = SUM(single_pages_kb + multi_pages_kb)


FROM sys.dm_os_memory_clerks


WHERE name = 'TokenAndPermUserStore'


 


-- Greater than 100MB


IF @CacheSize >= 100000


BEGIN


DBCC FREESYSTEMCACHE ('TokenAndPermUserStore')


RAISERROR ('Cleared TokenAndPermUserStore at %s, size = %dKB', 0, 1, @CurDate,


@CacheSize) WITH LOG


END


RAISERROR ('TokenAndPermUserStore size at %s: %dKB', 0, 1, @CurDate, @CacheSize)


WITH NOWAIT


WAITFOR DELAY '00:00:10'


END


 

Comments (0)

Skip to main content