IMetabaseObjectDescriptor.Cache

Syntax

Cache: IMetabaseObjectCache;

Description

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

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, the cached version of the object will be extracted and opened. If the record for the specified parameters is absent, the object will be opened. All objects, on which this object depends, will also be opened. Regular reports support caching of the object instance.

Object cache is stored in the repository database.

Example

Executing the example requires a form and the following components on the form: the Button1 button, the ReportBox component, and the UiReport component named UiReport1. The UiReport1 component is a data source for the ReportBox component. The repository contains a regular report with the Report_1 identifier.

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("Record in cache of: " + 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;
        //Delete old records from object cache
        If CacheItem.Timestamp < OldDate Then
            CacheItem.Flush;
        End If;
    End For;
    Debug.WriteLine("Records in cache created earlier than " + 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 development environment console displays information about the records in object cache. Date and time of creation and the list of values of parameters, with which the regular report was opened at that moment, are displayed for each record. The records that were created one month ago and earlier are deleted. If the records remain in cache after deletion, the object instance stored in the last remained record is loaded to the UiReport1 component. If all records are deleted from cache, the report opened from the repository is loaded to the UiReport1 component.

See also:

IMetabaseObjectDescriptor