Skip to content

Commit

Permalink
adding cache expiry mechanisms and fixing PD-237465, PD-237445 (#139)
Browse files Browse the repository at this point in the history
* adding cache expiry mechanisms and fixing PD-237465, PD-237445

* 2.9.2

* resolving review comments

* adding a debounce cache clean up function and and making changes to improve performance

* updating unit test cases with deletion test case

* resolving review comments
  • Loading branch information
VarshaAdigaBV authored Apr 9, 2024
1 parent e57371b commit 6713f93
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 89 deletions.
51 changes: 48 additions & 3 deletions lib/bvFetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,68 @@ The BvFetch module provides methods to cache duplicate API calls and interact wi

## BvFetch Parameters
`shouldCache (Function):` A function that takes the API response JSON as input and returns a boolean indicating whether to cache the response or not. This allows you to implement custom logic based on the response content. If caching is desired, the function should return true; otherwise, false.

`cacheName (String):` Optional. Specifies the name of the cache to be used. If not provided, the default cache name 'bvCache' will be used.
`cacheLimit (Integer)`: Optional. Specifies the cache size limit for the cache storage. Its value should be in MB. Default value is 10 MB.

## bvFetchFunc Method Parameters
`url (String):` The URL of the API endpoint to fetch data from.

`options (Object):` Optional request options such as headers, method, etc., as supported by the Fetch API.

## bvFetchFunc Return Value
`Promise<Response>:` A promise that resolves to the API response. If the response is cached, it returns the cached response. Otherwise, it fetches data from the API endpoint, caches the response according to the caching logic, and returns the fetched response.

## flushCache Method Parameters
## generateCacheKey Method Parameters:
`url (String):` The URL of the API endpoint.
`options (Object):` Optional request options.
## generateCacheKey Return Value:
`string:` The generated cache key.

## retrieveCachedUrls Method
Retrieves cached URLs from the cache storage associated with the provided cache name.
## retrieveCachedUrls Parameters
This method takes no parameters.
## retrieveCachedUrls Return Value
`void:` This method does not return anything.

## fetchDataAndCache Method
Fetches data from the specified URL, caches the response, and returns the response.
## Parameters
`url (String):` The URL from which to fetch data.
`options (Object):` Optional request options such as headers, method, etc., as supported by the
Fetch API.
`cacheKey (String):`
The cache key associated with the fetched data.
## Return Value
`Promise<Response>:` A promise that resolves to the fetched response.

## fetchFromCache Method
Function to fetch data from cache.
## Parameters
`cacheKey (String):` The cache key to fetch data from the cache.
## Return Value
Promise<Response|null>: A Promise that resolves with a Response object if the data is found in cache, or null if the data is not cached or expired.

## cacheData Method
Caches the provided response with the specified cache key if it meets the criteria for caching.
## Parameters
`response (Response):` The response object to be cached.
`cacheKey (String):` The cache key associated with the response.
## Return Value
`void:` This method does not return anything.


## flushCache Method Parameters
This method takes no parameters.
## flushCache Return Value
`Promise<void>:` A promise indicating the completion of cache flush operation.

## manageCache Method
Manages the cache by deleting expired cache entries and maintaining the cache size limit.
## Parameters
This method takes no parameters.
## Return Value
`void:` This method does not return anything.


## Usage with of `BvFetch`:

Expand Down
Loading

0 comments on commit 6713f93

Please sign in to comment.