Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the caching mechanism for the publisher restrictions in TCData class #4

Merged
merged 7 commits into from
Aug 29, 2022

Conversation

sevriugin
Copy link

@sevriugin sevriugin commented Aug 22, 2022

Description

To implement the caching mechanism we introduce in the IAB TCF cmpapi library two new classes: CacheBucket and Cache .

The CacheBucket class implements actual caching mechanism and provides get method that accepts cache key, recalculation function and recalculation functions parameters as arguments. The CacheBucket class also has a name property.

The Cache class implements a collection (map) of CacheBucket objects with several simple methods including the getBucket method to get/create CacheBucket using name string.

We need this two level structure to separate caching for two classes TCData and InAppTCData .

We use Cache class to create restrictionsCache in CmpApiModel singleton class that "... acts much like a global state or database, where CmpApi sets data and Commands read the data".

The TCData class uses restrictionsCache to get cache bucket using class name

const bucket = CmpApiModel.restrictionsCache.getBucket(this.constructor.name);

Now the publisher restrictions could be extracted from the CacheBucket or recalculated if consent string value is changed

const restrictions = bucket.get(this.tcString, this.createRestrictions.bind(this), tcModel.publisherRestrictions );

Summary of changes

  • CacheBucket class implemented;
  • Cache class implemented;
  • Update CmpApiModel class (singleton) to add restrictionsCache parameter;
  • Update TCData class to use restrictions cache from the singleton object CmpApiModel;
  • Add unit and integrations tests.

modules/cmpapi/src/Cache.ts Show resolved Hide resolved
modules/cmpapi/src/CacheBucket.ts Show resolved Hide resolved
modules/cmpapi/test/response/TCData.test.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants