最終更新日 :
2021年4月28日
CacheRemove(Object id, boolean throwOnError, String key, boolean exact)
関連項目
cfcache、CacheGet、CachePut、CacheGetAllIds、CacheGetProperties、CacheGetMetadata、CacheSetProperties
履歴
ColdFusion 11:ids パラメーターも配列を受け付けます。
ColdFusion 10:region 属性と {{exact}} 属性が追加されました。
ColdFusion 9: この関数が追加されました。
パラメータ
パラメータ |
説明 |
---|---|
id |
削除するキャッシュされたオブジェクトの ID を指定するカンマ区切りの文字列です。ColdFusion 11 からは ID の配列も指定できます。 |
throwOnError |
(オプション)指定された ID がキャッシュされた要素の ID でない場合に例外を返すかどうかを指定するブール値です。デフォルト値は false です。 |
key |
(オプション)削除対象のキャッシュされたオブジェクトが存在するキャッシュ領域の名前です。 |
exact |
(オプション)true の場合、(削除の)検索対象を ID と完全に一致する値に絞り込みます。デフォルト値は true です。 |
exact パラメーターを true に設定する場合の例
<!--- clear all object caches ---> <cfif ArrayLen(cacheGetAllIds()) gt 0> <cfset cacheRemove(ArrayToList(cacheGetAllIds()))> </cfif> <!--- create few caches ---> <cfloop from="1" to="10" index="i"> <cfset id = "cache_#i#"> <cfset timeToLive = CreateTimeSpan(0,0,30,0)> <cfset timeToIdle = CreateTimeSpan(0,0,30,0)> <cfset cachePut(id,createQryObj(i),timeToLive,timeToIdle)> </cfloop> <cfoutput>Before cacheRemove() :: Number of objects in the cache: #ArrayLen(cacheGetAllIds())#<br></cfoutput> <!--- clear all objects from the cache ---> <cfset cacheRemove("cache_1",true,"object",true)> <cfoutput>(List of cache Ids - #ListSort(ArrayToList(cacheGetAllIds()),"textnocase","ASC")#)</cfoutput><br> <cfoutput>After cacheRemove() :: Number of objects in the cache: #ArrayLen(cacheGetAllIds())#<br><br></cfoutput> <!--- create an obj to put into the cache ---> <cffunction name="createQryObj" hint="create a query object to put in the cache"> <cfargument name="loopIdx" type="numeric" required="yes"> <cfset var colList = ""> <cfset var alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]> <cfloop from="1" to="#loopIdx#" index="q"> <cfset colList = (len(colList) gt 0)? (colList & "," & "col#q#") : "col#q#"> </cfloop> <cfset var nbrCols = listlen(colList)> <cfset var qObj = querynew(colList)> <cfset queryaddrow(qObj,loopIdx)> <cfloop from="1" to="#loopIdx#" index="q"> <cfloop from="1" to="#nbrCols#" index="c"> <cfset querysetcell(qObj,"col#c#","#alphabet[randrange(1,arraylen(alphabet))]##randrange(1,1000000)#",q)> </cfloop> </cfloop> <cfreturn qObj> </cffunction>
exact パラメーターを false に設定する場合の例
<!--- clear all object caches ---> <cfif ArrayLen(cacheGetAllIds()) gt 0> <cfset cacheRemove(ArrayToList(cacheGetAllIds()))> </cfif> <!--- create few caches ---> <cfloop from="1" to="10" index="i"> <cfset id = "cache_#i#"> <cfset timeToLive = CreateTimeSpan(0,0,30,0)> <cfset timeToIdle = CreateTimeSpan(0,0,30,0)> <cfset cachePut(id,createQryObj(i),timeToLive,timeToIdle)> </cfloop> <cfoutput>Before cacheRemove() :: Number of objects in the cache: #ArrayLen(cacheGetAllIds())#<br></cfoutput> <!--- clear all objects from the cache ---> <cfset cacheRemove("cache_1",true,"object",false)> <cfoutput>(List of cache Ids - #ListSort(ArrayToList(cacheGetAllIds()),"textnocase","ASC")#)</cfoutput><br> <cfoutput>After cacheRemove() :: Number of objects in the cache: #ArrayLen(cacheGetAllIds())#<br><br></cfoutput> <!--- create an obj to put into the cache ---> <cffunction name="createQryObj" hint="create a query object to put in the cache"> <cfargument name="loopIdx" type="numeric" required="yes"> <cfset var colList = ""> <cfset var alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]> <cfloop from="1" to="#loopIdx#" index="q"> <cfset colList = (len(colList) gt 0)? (colList & "," & "col#q#") : "col#q#"> </cfloop> <cfset var nbrCols = listlen(colList)> <cfset var qObj = querynew(colList)> <cfset queryaddrow(qObj,loopIdx)> <cfloop from="1" to="#loopIdx#" index="q"> <cfloop from="1" to="#nbrCols#" index="c"> <cfset querysetcell(qObj,"col#c#","#alphabet[randrange(1,arraylen(alphabet))]##randrange(1,1000000)#",q)> </cfloop> </cfloop> <cfreturn qObj> </cffunction>