Hello, can't figure out how to cache files and never reload it in expandtemplate() ?
0 means - don't cache in wconnect.h
*** Determines whether TEMPLATE pages are cached (ExpandTemplate calls)
*** Note: This value specifies how often the file is checked for
*** a newer version in seconds. 0 means - don't cache.
#DEFINE WWC_CACHE_TEMPLATES 0
*** Read HTML from a disk file
#IF WWC_CACHE_TEMPLATES > 0
lcOutput = CacheFile(tcPageName,WWC_CACHE_TEMPLATES)
IF !EMPTY(lcOutput)
loEval = CREATE("wwScripting")
RETURN THIS.Write(loEval.MergeText(@lcOutput),tlNoOutput)
ELSE
RETURN THIS.Write(lcOutput+[<h2>Can't find or open page ]+JUSTFNAME(tcPagename)+[</h2>])
ENDIF
#ELSE
And we have to use 0 to never reload in Cachefile
************************************************************************
FUNCTION CacheFile
******************
*** Function: Caches read from disk in a cursor. Use like File2Var.
*** Assume: Using llCheckDate can worsen performance considerably
*** Pass: lcFileName - Name of the file to read/cache
*** lnRefreshSeconds - If the file cached is older than
*** the number of seconds specified
*** here it's reloaded. Use 0 to
*** never reload.
*** llMergeText - if .T. merges ASP style tags
*** on the content from the file
*** and stores result in the cache
*** Return: String of the file or ""
************************************************************************
LPARAMETERS lcFileName, lnRefreshSeconds, llMergeText
The cache is a cursor so if the (wwCache) cursor gets closed the cache gets released too. So make sure there's no code that closes the cache. Shutting down will close the cache as well as by default WWWC does CLOSE ALL at the end of the application.
+++ Rick ---
Thank you for your reply Rick, but the problem is to call the cachefile() function we have to set WWC_CACHE_TEMPLATES > 0 and to get never reload we have to put WWC_CACHE_TEMPLATES = 0. The solution of course will be to set WWC_CACHE_TEMPLATES to a large number of seconds, just wanted to pointed out the problem that we can put the value to WWC_CACHE_TEMPLATES = 0
Hmmm... maybe we should change the default value of WWC_CACHE_TEMPLATES
to -1
then change the code where it's used to > -1
. Since I can change this in the default wconnect.h
template this would be a non-breaking change unless somebody explicitly has the value overridden and set to 0 (which is unlikely since that was the default).
This would allow using 0 as the default value to caching indefinitely.
Adding the following in wconnect.h
:
*** Determines whether TEMPLATE pages are cached (ExpandTemplate calls)
*** Note: This value specifies how often the file is checked for
*** a newer version in seconds.
*** < 0 or -1 means - don't cache.
*** 0 means cache indefinitely.
*** > 0 means number of seconds to cache
#DEFINE WWC_CACHE_TEMPLATES -1
And then updating wwPageResponse
and wwResponse
to:
*** Read HTML from a disk file
#IF WWC_CACHE_TEMPLATES > -1
lcOutput = CacheFile(tcPageName,WWC_CACHE_TEMPLATES)
+++ Rick ---