IMetabaseObjectDescriptor.Cache

Syntax

Cache: IMetabaseObjectCache;

Description

The Cache property returns a collection of the records of the repository object cache.

Comments

Object cache contains instances of the object that was opened with the determined values of parameters. Presence of record that corresponds to these parameters in the cache is checked when opening the object with any parameters. If the record is found, it will be extracted and the cached version of the object will be opened. If the record for the specified parameters is not present, the object will be opened. All objects on which this object depends, will also be opened. Regular reports support caching of the object instance.

The object cache is stored in the repository base.

Example

Executing the example requires a form with the Button1 button, the ReportBox component and the UiReport component named UiReport1. The UiReport1 component is a source of data for the ReportBox component. There is a regular report with the "Report_1" identifier in the repository.

Add links to the Metabase, Ui system assemblies.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    MB: IMetabase;
    MDesc: IMetabaseObjectDescriptor;
    Cache: IMetabaseObjectCache;
    CacheItem: IMetabaseObjectCacheItem;
    Params: IMetabaseObjectParamValues;
    Param: IMetabaseObjectParamValue;
    OldDate: DateTime;
Begin
    MB := MetabaseClass.Active;
    MDesc := MB.ItemById("Report_1");
    Cache := MDesc.Cache;
    OldDate := DateTime.AddMonths(DateTime.Now, -1);
    Debug.WriteLine("Object cache contents: " + MDesc.Id);
    Debug.Indent;
    For Each CacheItem In Cache Do
        Debug.WriteLine("Records in cache from: " + CacheItem.Timestamp.ToString);
        Params := CacheItem.ParamValues;
        If Params.Count <> 0 Then
            Debug.WriteLine("Object parameters:");
            For Each Param In Params Do
                Debug.WriteLine("Parameter: " + Param.Name + "(" + Param.Id + ") = " + Param.Value);
            End For;
        End If;
        //Remove old records from object cache
        If CacheItem.Timestamp < OldDate Then
            CacheItem.Flush;
        End If;
    End For;
    Debug.WriteLine("Records in cache with creation date before " + OldDate.ToString + " were deleted.");
    If Cache.Count <> 0 Then
        UiReport1.Instance := Cache.Item(Cache.Count - 1).Open;
    Else
        UiReport1.Instance := MDesc.Open(Null);
    End If;
    Debug.Unindent;
End Sub Button1OnClick;

After executing the example the information about the records in the object cache is displayed in the development environment console. Date and time of creation and the list of values of parameters with which the regular report was opened in that moment are displayed for each record. Records that were created more than one month ago, are removed. If the records remain in cache after removal, the object instance that stored in the last remained record is loaded into the UiReport1 component. If all records are removed in cache, the report opened from repository is loaded into the UiReport1 component.

See also:

IMetabaseObjectDescriptor