Skip to content

Instantly share code, notes, and snippets.

@kordero
Created December 8, 2015 23:40
Show Gist options
  • Save kordero/074e831b185510ea548b to your computer and use it in GitHub Desktop.
Save kordero/074e831b185510ea548b to your computer and use it in GitHub Desktop.
MEMFacts I/O cache

MEMFacts Input/Output cache

Input

Input cache helps reducing page speed loads since it avoids to have visitors waiting for the server to do necesary requests to data server or file reads in order to get all the data it needs to render the output. This behavior consist in saving every needed input in a temporary memory in order to be reused if they are needed before a predefined amount of time has passed.

API Requests

st=>start: Dataset fetch call
datasetCached=>condition: dataset cached?
apiRequest=>inputoutput: API request
save=>subroutine: save result in cache:
API_CACHE_TIME_TO_LIVE
e=>end: Return dataset

st->datasetCached(yes)->e
st->datasetCached(no)->apiRequest
apiRequest(right)->save->e

File / disk reads

st=>start: File content request
fileCached=>condition: content cached?
apiRequest=>inputoutput: File is read
save=>subroutine: save content in cache:
FILE_CACHE_TIME_TO_LIVE
e=>end: Return content

st->fileCached(yes)->e
st->fileCached(no)->apiRequest
apiRequest(right)->save->e

Output

Once a specific page has been processed, the outputed content is also cached in order to avoid unnecesary CPU process. This means that subsecuent calls to the controller will output its content directly and will not execute any code from that controller if it was called with exact same parameters.

st=>start: Page request
outputCached=>condition: output cached?
apiRequest=>inputoutput: Controller is ran
save=>subroutine: save output in cache:
OUTPUT_CACHE_TIME_TO_LIVE
e=>end: Output content

st->outputCached(yes)->e
st->outputCached(no)->apiRequest
apiRequest(right)->save->e

Environment-specific cache setting

Production

Staging

Development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment