Parse-cache-memory - A cache library customized for parse-server queries

Some features were added and new using styles like this one. The package version should least 1.0.13

require('parse-cache-memory').parseCacheInit();

or

const customOptions = {
  max: 1000, // maximum number of items that can be stored for each class (className)
  maxSize: 10000, // total maximum number of items that can be stored across all classes
  ttl: 1000 * 60 * 10, // time-to-live for items in the cache, here set to 10 minutes
  allowStale: true, // determines whether items can be used after their ttl has expired
  updateAgeOnGet: true, // determines whether an item's age is updated when it's retrieved using "get"
  updateAgeOnHas: true, // determines whether an item's age is updated when it's checked using "has"
  resetCacheOnSaveAndDestroy: false, // determines whether the cache is reset when an object is saved or destroyed
};
const ParseCache = require('parse-cache-memory').parseCacheInit(customOptions)
1 Like

Hi rgunindi,

Sometimes I get this error, not sure if that’s related to my code implementation or a bug.

TypeError: Cannot read properties of undefined (reading 'className')
    at global.Parse.Object.saveAll (C:\Users\PC\Desktop\project\backend\node_modules\parse-cache-memory\index.js:77:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async updateUniqueStats (C:\Users\PC\Desktop\project\backend\cloud\functions\common\updateStatsOnDelivery.js:59:7)

Node.js v18.2.0

It happens out of nowhere, even if not using the cached function. Maybe that’s because parse-cache-memory probably overrides standard Parse.Object.saveAll function.

Edit: the issue is indeed package related and happens only when Parse.Object.saveAll function is used (Tested after uninstalling the package - works fine).

1 Like

Hi andreisu,

During the save process if it doesn’t pass className this error will return.
If you update the package to 1.0.13, the default cache will not reset.
This mentioned provides this option
resetCacheOnSaveAndDestroy: false
This error throws in some parse versions, so this is a good option for these variations.

1 Like

Ok, I just updated to 1.0.13. it works perfect. Thank you.

1 Like

Thanks, Did you use .parseCacheInit() function ?

yes, I did it like you showed above

1 Like

Updated new version 2.0

don`t forget update because deprecated old versions.