/workspace/cache

The module exports the cacheWorkspace method which returns a workspace from the module scope cache variable or call the cacheWorkspace method to cache the workspace.

Default templates can be overwritten in the workspace or by providing a CUSTOM_TEMPLATES xyzEnvironment variable which references a JSON with templates to be merged into the workspace.

Requires

Methods

(inner) assign_workspace_templates(workspace_templates, templates_object, typeopt) → {Object}

The method assigns objects in a templates object to the workspace.templates provided as workspace_templates param.

Parameters:
NameTypeAttributesDefaultDescription
workspace_templatesobject

The workspace.templates object.

templates_objectObject

An object of templates to be assigned with the template key to the workspace templates.

typestring<optional>
'core'

The type value to assign to the template to identify the origin.

Returns:

templates_object with _core: true property.

Type: 
Object

(inner) cacheWorkspace() → {workspace}

The workspace is retrived from the source defined in the WORKSPACE xyzEnvironment variable.

Templates defined in the CUSTOM_TEMPLATES xyzEnvironment variable are spread into the default workspace.templates{}.

Each locale from the workspace.locale{} is merged into the workspace.locale{} template.

Locale objects get their key and name properties assigned if falsy.

The workspace is assigned to the module scope cache variable and the timestamp is recorded.

Returns:

JSON Workspace.

Type: 
workspace

(inner) checkWorkspaceCache(forceopt) → {workspace}

The method checks whether the module scope variable cache has been populated.

The timestamp set by cacheWorkspace is checked against the current time. The [workspace] cache will be invalidated if the difference exceeds the WORKSPACE_AGE xyzEnvironment variable.

Setting the WORKSPACE_AGE to 0 is not recommended as this could cause the cache to be flushed while a request is passed through the XYZ API. A layer query processed by the Query API module will request the layer and associated locale which could be defined in remote templates. Each request to the Workspace API getTemplate method for the locale, layer, and query templates will call the checkWorkspaceCache method which will cause the workspace to be flushed and templates previously cached from their src no longer available.

The cacheWorkspace method is called if the cache is invalid.

Parameters:
NameTypeAttributesDescription
forceboolean<optional>

The workspace cache will be cleared with the force param flag.

Returns:

JSON Workspace.

Type: 
workspace