Symphony Framework
Symphony DOCache v3.2
Symphony Templates > Symphony DOCache v3.2
Template file name Symphony_DOCache_v3_2.tpl

The Symphony_DOCache (version 3.2) template generates a static class that allows the caching of Data Objects.  Accessing a data object through the DOCache class first checks if the Data Object has previously been read from the data source.  If so, this cached copy is returned.  If not, the requested Data Object is loaded from the data source, stored in the cache and returned.

The data source is a Synergy.SynergyDE.Select instance using the defined filename.

This class is very useful for retrieving commonly used data objects that remain constant through the life of the application.  For example address details of a contact.  The cache prevents repeated access of the physical data file.
To clear the cache call the InitCache() method.
It is recommended that your generated code from the Symphony_DOCache template is created into a project sub-folder called Data.
 CodeGen Template Tokens
Token Comments
NAMESPACE Define the namespace within which the generated class will be placed (-n option).
 Symphony Tokens
             

Symphony tokens are applied to fields in the repository in the Long Description.  They allow for additional field processing by CodeGen.  You must define both the token and value, enclosed within <> brackets.  For example <SYMPHONY_MAX_DISPLAY_LENGTH=100>

You can define any number of Symphony tokens in the long description.  There is no separation character required.

   
Token Comments
MODELNAMESPACE The namespace within your application that contains the structure specific Data Object class the generated code will use while reading data from the data file.
DATAFILENAME Override the standard <FILE_NAME> CodeGen token.  This can be a literal filename or the name of a static method/function that returns a computed filename.
 CodeGen Command Examples
Data object
codegen e -r -s PART -t Symphony_DOCache_v3_2 -o %ROOT%ControlLibrary\Data -n ControlLibrary.Data -ut MODELNAMESPACE=ControlLibrary.Data
       
 Example
;;****************************************************************************
;; WARNING: This code was code generated. Any changes that you
;;          make to this code will be overwritten if the code is regenerated!
;;
;; Template author:    Richard C. Morris : RCP Consultants.
;;
;; Template Name:    Symphony Framework : SYMPHONY_DOCACHE_V3_2.tpl
;;****************************************************************************


import System
import System.Collections.Generic
import System.Text

import Synergex.SynergyDE.Select
import ControlLibrary.Data

namespace ControlLibrary.Data
    
    public class Part_DOCache
        
        private static mObjectCache    ,@Dictionary<String, Part_Data>    ,new Dictionary<String, Part_Data>()
        
        public static method DataObject    ,@Part_Data
            in req keyValue        ,String
            endparams

        proc
            data partRecord    ,STRPart
            data doObject    ,@Part_Data
            if (!mObjectCache.TryGetValue(partRecord.str_id = keyValue, doObject))
            begin
                ;;object not found in dictionary, load it.
                foreach partRecord in new Select(new From("SYMPHONYDATA:parts.ism", partRecord),
                &    (Where) partRecord.str_id .eqs. keyValue
                &    )
                begin
                    doObject = new Part_Data(partRecord)
                    mObjectCache.Add(
                    &    partRecord.str_id
                    &    , doObject)
                    exitloop
                end
            end
            
            mreturn doObject
        endmethod
        
        public static method InitCache, void
            endparams
        proc
            mObjectCache.Clear()
        endmethod

    endclass
    
endnamespace
See Also

Reference