Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ApiDataCacheService<T>

Type Parameters

  • T

Hierarchy

  • ApiDataCacheService

Index

Constructors

  • Create a Cached Data Service.

    Type Parameters

    • T

    Parameters

    • httpProxy: any

      A class implementing the Angular HtttpClient methods get,patch,post, delete and request.

    • url: string

      The base CRUD url.

    • cacheTTL: number = 100

      The data cache time to live. (default 100 seconds, minimum 10 seconds)

    • options: DataCacheOptions = {}

      Additional endpoint for filtering operations used in the advancedList method.

    Returns ApiDataCacheService<T>

Properties

cachedVersionInfo: {} = {}

Type declaration

  • [id: string]: any[]
disabledCache: boolean = false

Disable new updates to be cached.

requestHeaders: {} = {}

Set additional headers to all requests of the service.

Type declaration

    serializer: ((data: any) => {})

    Type declaration

      • (data: any): {}
      • Function to serialize the instance data before sending to serve in the edit() and create() methods.

        Parameters

        • data: any

        Returns {}

      setFullRecordOnGet: boolean = true

      By setting the parameter setFullRecordOnGet to true, the retrieved record using the get() method will be automatically marked as full. In this context, 'full' means that the record possesses all fields, including any required nested fields. On the other hand, if setFullRecordOnGet is set to false, the retrieved record will not be marked as 'full'. In this case, you need to add a calculated field _full: true to the fully serialized records on the server-side.

      started: boolean = false

      Is the data service initiated?

      url: string

      Methods

      • This method constucts a POST request that retrives a list of selected entity instances. The selecting parameters are passed in the request body through the parameter options. These parameters must be interpreted by the backend. In principle this method should be used in list views where the server would return non-nested or partial objects.

        see

        list

        example
        // Filtering
        let bakersList = [];
        const options = { filter: {'profession': 'Baker'}};
        service.advancedList('', options)
        .subscribe( r => bakersList = r.list);

        // Inclusion of instances
        let bakersListExtended = [];
        const options = { filter: {'profession': 'Baker'}, includeIds: [3, 4, 5]};
        service.advancedList('', options)
        .subscribe( r => bakersListExtended = r.list);

        // Fully-nested objects
        let detailedBakersList = [];
        const options = { filter: {'profession': 'Baker'}, fullyNested: true};
        service.advancedList('', options)
        .subscribe( r => detailedBakersList = r.list);

        Parameters

        Returns Subject<DataListResponse<T>>

        An Observable of the response.

      • Constructs a POST request to create a new entity record in the server database.

        Parameters

        • instance: Partial<T>

          partial instance of object.

        Returns Observable<DataCreationResponse<T>>

        An Observable of the response. If the server response includes the data of the created record, this data will be cached.

      • Constructs a PATCH request to update an existing record in the server database.

        Parameters

        • id: number | DataModel

          Unique identifier of the entity record.

        • alternativeUrl: string = ''

        Returns Observable<any>

        An Observable of the response. If the server response includes the data of the created record, this data will update the cache.

      • deleteOutdatedCache(): void
      • Free memory by deleting outdated instances from the cache.

        Returns void

      • Constructs a PATCH request to update an existing instance in the server database.

        Parameters

        • instance: Partial<T>

          partial record of object.

        • alternativeUrl: string = ''

        Returns Observable<any>

        An Observable of the response. If the server response includes the data of the created instance, this data will update the cache.

      • get(id: string | number, reload?: boolean, alternativeUrl?: string): Observable<T>
      • Constructs a GET request that retrieves the entity's fully nested data by its unique identifier (id) and saves it in the data cache, reducing the number of server accesses. The default URL endpoint is used, appended by "/${id}/".

        If the property setFullRecordOnGet is set to true, the retrieved record will automatically receive an extra field _full=true, indicating that the record contains all fields and required nested fields. This method will always request the server if the _full field of the record is set to false.

        Parameters

        • id: string | number

          The unique identifier of the entity instance.

        • reload: boolean = false

          false: Get data from the local cache if available. true: Get data from the server and update the local cache.

        • alternativeUrl: string = ''

          An alternative endpoint URL.

        Returns Observable<T>

        An Observable of the service response.

      • initiateService(): void
      • Constructs a GET request that retrives a list of entity instances. In principle this method should be used to fetched non-nested or partial objects. The fully nested object could be retrived in the detail view by using the method get().

        see

        get

        Parameters

        Returns Subject<any> | Observable<T[] | DataListResponse<T>>

        An Observable of the response.

      • markAllOutdated(): void
      • markOutdated(id: string | number): void
      • Mark cached record as outdated

        Parameters

        • id: string | number

          Instance id to be marked as outdated.

        Returns void

      • resetListResponseCache(): void
      • Delete short-lived server response cache. This data cache is only used for listing, common in pagination operations.

        Returns void

      • searchCache(qsearch: string, scopeIds?: number[]): any[]
      • Search instances locally.

        Parameters

        • qsearch: string

          String to search in the object fields.

        • scopeIds: number[] = []

          Limiting search to specific collection of ids.

        Returns any[]

        The cached items that matches the search input.

      • updateItemsMetaCache(items: any[], updatingTime?: any): T[]
      • Parameters

        • items: any[]
        • updatingTime: any = null

        Returns T[]

      Generated using TypeDoc