express icon indicating copy to clipboard operation
express copied to clipboard

feat: add cache to defineGetter

Open nigrosimone opened this issue 1 year ago • 1 comments

Adding this cache to the defineGetter function has several implications:

  • Performance Improvement: The getter function will only be called once, and its result will be stored. Subsequent accesses to the property will return the cached value, avoiding the cost of repeatedly executing the getter function.
  • Consistency: The value returned by the getter will remain consistent for the lifetime of the property on the object. If the getter logic involves any computation that could potentially change, this cache will prevent any changes from being reflected in the property's value after the first access.
  • Side Effects: If the getter function has side effects (e.g., logging, triggering other operations), these will only occur once when the value is first computed. Subsequent accesses will not trigger these side effects.

Just for POC, I have enabled only on query

nigrosimone avatar Oct 12 '24 07:10 nigrosimone

Referencing https://github.com/expressjs/discussions/pull/306

IamLizu avatar Jan 15 '25 09:01 IamLizu