I know I can use ColdFusion cache APIs to clear data as such:
<cfset cacheName = "custom">
<cfset ids = cacheGetAllIds(cacheName)>
<cfset cacheRemove(arrayToList(ids), false, cacheName)>
But in practice retrieving all the ids (i.e. cacheGetAllIds()
) to do the deletion is slow (e.g. seconds). Where I'm thinking there should be a way if I'm completely starting over to have this happen in milliseconds开发者_如何学Go. In my particular case the custom cache is disk persistent and can be 100s of megabytes on disk.
I'm suspecting there's a faster way to clear this out using methods on cacheGetSession()
, perhaps in conjunction with ColdFusion APIs. So asking to see if someone has some knowledge of how to do this, and make ColdFusion happy at the same time, before I start looking under the hood myself.
Update
Looks like it might be possible to use cacheGetSession(cacheName, true).removeAll() because the object returned is of type net.sf.ehcache.Cache, which implements net.sf.ehcache.Ehcache. And this interface specifies a method removeAll(). Haven't tried it out yet though.
This does it:
cacheGetSession(cacheName, true).removeAll()
With about 10K+ records it returned in 60 ms.
FYI: cachGetSession() is a ColdFusion 9.0.1 function
I haven't tested this, but is this any faster? Just in case ArrayToList()
is the bottleneck.
<cfloop index="cache" array="#cacheGetAllIds(cacheName)#">
<cfset cacheRemove(cache, false, cacheName)>
</cfloop>
reference: http://www.aaronwest.net/blog/index.cfm/2009/11/28/14-Days-of-ColdFusion-9-Caching-Day-12--Removing-All-Items-in-Cache
If performance is really an issue for you, file a bug report? http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html
精彩评论