I have activated rlm_cache so as to reduce the amount of times the freeradius will query the DB. I made the Calling-Station-Id the cache key and have added this code to the accounting section: cache if (ok){ sql } else { if ("%{sql:select case when exists(select * from [TABLE_NAME] where ne_id='%{Calling-Station-Id}') then 1 else 0 end}" == 1){ sql } } However what happens is that all Calling-Station-Ids are stored to the cache and so the 2nd time I get a packet they execute the sql module. How can I configure filtering of the cache in the “else” section so as to decide which Calling-Station-Id to save in cache and which not? Thanks Liran