
[dbo].[CleanExpiredCache]
CREATE PROCEDURE [dbo].[CleanExpiredCache]
AS
DECLARE @now as datetime
SET @now = DATEADD(minute, -1, GETDATE())
UPDATE SN
SET
PermanentRefcount = PermanentRefcount - 1
FROM
[ReportServerTempDB].dbo.SnapshotData AS SN
INNER JOIN [ReportServerTempDB].dbo.ExecutionCache AS EC ON SN.SnapshotDataID = EC.SnapshotDataID
WHERE
EC.AbsoluteExpiration < @now
DELETE EC
FROM
[ReportServerTempDB].dbo.ExecutionCache AS EC
WHERE
EC.AbsoluteExpiration < @now
GO
GRANT EXECUTE ON [dbo].[CleanExpiredCache] TO [RSExecRole]
GO