I'm working on reducing data storage space and increasing the amount of automation for an integration with an external system. The relevant part of that integration for this question is a sync of product pricing information. This external system gives us about 120k rows for product pricing (~400 partners that resell our ~300 products). Each row contains 1 price for 1 product for 1 partner.
This product pricing information is effectively static, so I thought that the platform cache would be a good way to allow me to store this information and allow me to (immediately) delete the individual product pricing records (from Salesforce, not the external system)1.
A few iterations later, and I'm consolidating these 120k product pricing records into ~400. One per partner, which contain a serialized map of product Id to a price (in a longTextArea field). These ~400 (SObject) records act as the backing to my cache, and I've created a class that implements the CacheBuilder
interface so I don't need to worry about cache misses. Also worthy of note is that the sum of this consolidated data is currently ~4MB.
The thing I'm concerned about is that when using a CacheBuilder, it appears that we can only retrieve a single key from the cache at a time and every miss is currently causing 1 query to be run. I don't think it's outside the realm of possibility for us to run into the 101 SOQL query limit, so I'd like to pre-warm the platform cache (i.e. put records I know I'm about to use into the cache before calling Cache.Session.get(MyCacheBuilder.class, 'my key');
)
I fire up the trusty dev console, and execute something like the following:
CachePartition cp = Cache.Session.getPartition('MyPartitionName');
cp.put('myKey', 'abc123');
System.debug(cp.get(MyCacheBuilder.class, 'myKey'));
To my surprise, the debug says that there is no cached value for 'myKey'
, and I've used a query to boot. Further inspection using cp.getKeys()
shows me that I have 2 keys in the cache, 'myKey'
and 'MyCacheBuilder_B_myKey'
.
So using a CacheBuilder prepends data to the key, and that's something Salesforce handles transparently. The issue is that we don't have a put(CacheBuilder, key, value)
method, and the key for put(key, value)
doesn't allow underscores, which is really stymying my attempt to pre-warm the cache.
Is there a way to populate the cache (without using get(CacheBuilder.class, key)
so that I can fetch values using get(CacheBuilder.class, key)
?
1: Yes, I'm aware that a Platform Event is probably a better choice here, given that I'm immediately deleting the record after some light processing. I'm trying to keep things relatively consistent (let's call it a soft requirement), and using a PE for just that one piece is unpalatable to my boss.