Has anyone considered this concept in NetSuite? `...
# suitescript
c
Has anyone considered this concept in NetSuite?
Memoization is a computer programming optimization technique that speeds up programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again
I want to add a beforeSave() function to journal records so I can map/swap account IDs before a journal is saved. I have the mapping stored in a custom record; I'm looking at ways to make this as quick as possible. Are N/cache reads quicker than searches or record loads? I could always store the mapping in the cache based on what's in the mapping table/record. If the mapping record changes, I can force the new values into the cache and expire the old values.
s
I think N/Cache is faster than searches or loading custom records. So it’s a good fit for your account-mapping logic on journals.
c
N/cache
works great for this sort of stuff. Once cached, lookups happen in a few milliseconds.
t
Are you saying you’ll store in cache indefinitely? That might be a big dependency
c
No
A UE script will purge and hydrate the cache whenever there is a change and if we get a cache miss, we will purge/hydrate again.
So yes, it will always be used, but I won't assume the data is always there.
t
So is it like? You hydrate the cache first, store it for some time let’s say a day, So whenever your userevent will run, it will fetch from cache rather than doing a search, and if you don’t find it. you’ll fetch again using a search. Sounds smart, however I do see one issue here, which can be resolved as well. If there is a change is account mapping, and Cache has previous mapping it might result in incorrect GL postings.
Checking if any changes were there is account mapping will eat out the time you saved.
c
@tuli A proper implementation of
N/cache
along with a UE script handles this very cleanly and efficiently.
t
Well It will definitely do as you said, there might something to track account mapping changes without time delay? Can you think of something? I am curious
c
@tuli the solution is easy, if the mapping record changes, you expire the old cache and re-hydrate.
You could also make the script check the mapping record changed date, if that date is newer than a stored date, expire the cache. There are lots of cache expiry strategies that can be used.