Permission denied Same Records Cache

Same Records Cache

if( NOT StructKeyExists(request,'params') ) request.params = StructNew(); if( NOT StructKeyExists(request.params,'action') ) request.params.action = 'RebuildJustBeforeExpiration'; if( NOT StructKeyExists(request.params,'rebuildMinutesBeforeExpire') ) request.params.rebuildMinutesBeforeExpire = 1; // 1 minute if( NOT StructKeyExists(request.params,'rebuildTimeout') ) request.params.rebuildTimeout = 30; // 30 seconds WriteOutput('
Rebuild Minutes Before Expire: #encodeForHTML(request.params.rebuildMinutesBeforeExpire)#'); WriteOutput('
Rebuild Timeout: #encodeForHTML(request.params.rebuildTimeout)#'); LogIt( "Param Cache Rebuild Job ran. Parameters: RebuildMinutesBeforeExpire:[#request.params.rebuildMinutesBeforeExpire#] RebuildTimeout:[#request.params.rebuildTimeout#] " );
types = StructKeyList(application.CS_SameRecordsCache); type = ListGetAt(types,t); // If custom element, query to figure out when the last time the element was updated. // If not updated after cache was written, cache is still good and can be extended // For non-custom elements make update date now to force cache rebuild if about to expire. elementLastUpdated = now(); if( FindNoCase('custom:', type ) ) { elementTypeID = getElementIDGivenName(type); if( elementTypeID ) elementLastUpdated = getElementTypeLastUpdate(elementTypeID); } WriteOutput('

#type# (Last Updated:#dtf(elementLastUpdated)#)

'); WriteOutput('
'); WriteOutput('
Time
'); WriteOutput('
Element Name
'); WriteOutput('
Created
'); WriteOutput('
Last Use
'); WriteOutput('
Rebuild Time
'); WriteOutput('
Expires
'); WriteOutput('
Secs
'); WriteOutput('
Hit Count
'); WriteOutput('
Status
'); WriteOutput('
Actions
'); WriteOutput('
'); // get list of element names elements = StructKeyList(application.CS_SameRecordsCache[type]);
elementName = ListGetAt(elements,i); expires = application.CS_SameRecordsCache[type][elementName].expires; rebuildTime = DateAdd('n', -request.params.rebuildMinutesBeforeExpire, expires); secBeforeRebuild = DateDiff( 's', now(), rebuildTime ); hitCount = application.CS_SameRecordsCache[type][elementName].hitCount; created = application.CS_SameRecordsCache[type][elementName].created; lastuse = application.CS_SameRecordsCache[type][elementName].lastuse; pageurl = application.CS_SameRecordsCache[type][elementName].pageurl; if( DateCompare( elementLastUpdated, created ) eq 1 ) status = 'Stale'; else status = 'Valid'; if( DateCompare( now(), expires ) eq 1 ) status = 'EXPIRED'; else if( secBeforeRebuild lt 0 ) status = 'REBUILDING'; if( Find( "?", pageurl ) eq 0 ) { relativeurl = pageurl & "?forceRender=1"; fullurl = CGI.http_host & pageurl & "?forceRender=1"; } else { relativeurl = pageurl & "&forceRender=1"; fullurl = CGI.http_host & pageurl & "&forceRender=1"; } WriteOutput('
'); WriteOutput('
#TimeFormat(now(),"HH:mm:ss")#
'); WriteOutput('
#ElementName#
'); WriteOutput('
#dtf(created)#
'); WriteOutput('
#dtf(lastuse)#
'); WriteOutput('
#dtf(rebuildTime)#
'); WriteOutput('
#dtf(expires)#
'); WriteOutput('
#secBeforeRebuild#
'); WriteOutput('
#hitCount#
'); WriteOutput('
#status#
'); if( status eq 'REBUILDING' ) WriteOutput('
 
'); else WriteOutput(''); WriteOutput('
');
// cache is about to expire if( DateCompare( now(), rebuildTime ) eq 1 AND DateCompare( now(), expires ) eq -1 ) { if( DateCompare( elementLastUpdated, created ) neq 1 ) { // element has NOT been updated since cache was created. Cache is still good. Extend the expiration date. application.CS_SameRecordsCache[type][elementName].expires = DateAdd( 'n', application.CS_SameRecordsCache[type][elementName].minutesToCache, now() ); WriteOutput('
Element not updated. Extending cache to #dtf(application.CS_SameRecordsCache[type][elementName].expires)#
'); LogIt( "Element Type not updated since #dtf(elementLastUpdated)#. Extending cache for '#elementName#' to #dtf(application.CS_SameRecordsCache[type][elementName].expires)#" ); } else { // The element was updated since the cache was built. Invoke the page to rebuild. status = requestPage( fullurl, request.params.rebuildTimeout ); WriteOutput('
Rebuilt #fullURL# #status#
'); LogIt( "Rebuilt about to expire [#dtf(expires)#] #status#" ); } } // cache is expired else if( DateCompare( now(), expires ) eq 1 ) { if( DateCompare( elementLastUpdated, created ) neq 1 ) { // element has NOT been updated since cache was created. Cache is still good. Extend the expiration date. application.CS_SameRecordsCache[type][elementName].expires = DateAdd( 'n', application.CS_SameRecordsCache[type][elementName].minutesToCache, now() ); WriteOutput('
Element not updated. Extending cache to #dtf(application.CS_SameRecordsCache[type][elementName].expires)#
'); LogIt( "Element Type not updated since #dtf(elementLastUpdated)#. Extending cache for '#elementName#' to #dtf(application.CS_SameRecordsCache[type][elementName].expires)#" ); } // Rebuild - for some reason we did not get to it // only try rebuilding if expired with the limit specified in reverse else if( DateCompare( now(), DateAdd( 'n', request.params.rebuildMinutesBeforeExpire, expires) ) eq -1 ) { // invoke page status = requestPage( fullurl, request.params.rebuildTimeout ); WriteOutput('
Rebuilt expired #fullURL# #status#
'); LogIt( "Rebuilt expired [#dtf(expires)#] #status#" ); } } else { // if Element has been updated since cache was created and Action = RebuildImmediately if( request.params.action eq 'RebuildImmediately' AND DateCompare( elementLastUpdated, created ) eq 1 ) { // invoke page status = requestPage( fullurl, request.params.rebuildTimeout ); WriteOutput('
Element Type changed on #dtf(elementLastUpdated)#. Rebuilt cache #fullURL# #status#
'); LogIt( "Element Type changed on #dtf(elementLastUpdated)#. Rebuilt cache. #status#" ); } } WriteOutput('');
var ret_url = ''; var qry = ''; select SitePages.Filename, Subsites.subsiteurl from SitePages, Subsites where SitePages.SubsiteID = Subsites.ID AND SitePages.ID = if( qry.recordcount eq 1 ) ret_url = qry.subsiteurl & qry.filename; logIt("Error in GetPage() - #cfcatch.message# #cfcatch.detail#"); var start = 0; var end = ''; var tc = 0; sleep(3000); // sleep for 3 seconds before building to ensure we don't flood the system if may items neeed to be rebuilt start = GetTickCount(); end = GetTickcount(); tc = end - start; logIt("Rebuilt #attributes.fullurl# [#cfhttp.statusCode#] [#tc# ms]"); logIt( "Error in requestPage() - #cfcatch.message# #cfcatch.detail#" ); var elType = ReplaceNoCase(arguments.name, 'custom:', '' ); var qry = ''; var retID = 0; // Build memory cache structure so we don't have to run query on every run of background job if( NOT StructKeyExists( application,'CS_SameRecordsCacheElementNames' ) ) application.CS_SameRecordsCacheElementNames = StructNew(); if( StructKeyExists( application.CS_SameRecordsCacheElementNames, elType ) ) retID = application.CS_SameRecordsCacheElementNames[elType].elementTypeID; else { application.CS_SameRecordsCacheElementNames[elType] = StructNew(); application.CS_SameRecordsCacheElementNames[elType].elementTypeID = 0; } select ID from AvailableControls where ShortDesc = Name = if( qry.recordcount eq 1 ) { // set ID to return retID = qry.ID; // cache off so query is not needed next time application.CS_SameRecordsCacheElementNames[elType].elementTypeID = qry.ID; } var qry = ''; select Max(DateApproved) As DateApproved from Data_FieldValue where FormID = AND VersionState = 2 var filename = expandPath( "/commonspot/logs" ) & "/" & DateFormat( now(), "yyyymmdd" ) & "-same-records-cache.log";