@mui/x-data-grid-pro
Version:
The Pro plan edition of the Data Grid components (MUI X).
43 lines (42 loc) • 963 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridDataSourceCacheDefault = void 0;
function getKey(params) {
return JSON.stringify([params.paginationModel, params.filterModel, params.sortModel, params.groupKeys]);
}
class GridDataSourceCacheDefault {
constructor({
ttl = 300000
}) {
this.cache = void 0;
this.ttl = void 0;
this.cache = {};
this.ttl = ttl;
}
set(key, value) {
const keyString = getKey(key);
const expiry = Date.now() + this.ttl;
this.cache[keyString] = {
value,
expiry
};
}
get(key) {
const keyString = getKey(key);
const entry = this.cache[keyString];
if (!entry) {
return undefined;
}
if (Date.now() > entry.expiry) {
delete this.cache[keyString];
return undefined;
}
return entry.value;
}
clear() {
this.cache = {};
}
}
exports.GridDataSourceCacheDefault = GridDataSourceCacheDefault;
;