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)

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).

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.

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

Thanks, Did you use .parseCacheInit() function ?

yes, I did it like you showed above

Updated new version 2.0

don`t forget update because deprecated old versions.

@rgunindi there’s any way to implement that using redis?

@yurilawnguru Actually, I can add Redis support but this concept began with lru-cache, currently, redis cannot be used directly.

@rgunindi
Redis support would be awesome. Some use Parse Server behind a load balancer with a lot of replicas. Need a distributed cache for that to work.

Forked your package since I wanted to add that myself, but I’m still using a single replica Parse Server so I don’t have an immediate need for it :stuck_out_tongue:

@jimnor0xF The sound is great! On one day if you add that will be grate :slight_smile:

Hi Everyone…

  • Added cache stats monitoring
  • More clear documentation.
  • Debug mode for monitoring each cache utility

Just for information for users.