You need to sign in to do that
Don't have an account?

Cache Session does NOT retrieve data stored in cache intermittently
We have identified an issue where Cache.Session get() method does NOT return data stored in cache intermittently. We have put together a very tiny sample VisualForce page to demonstrate the problem. This sample page demonstrates that Cache.Session.getPartition(partitionName).get(KEY) returns NULL even if the data exists in cache for the given KEY. The page performs 100 Visualforce.remoting.Manager.invokeAction calls to a controller remote action. If the Apex code is not able to retrieve the data from cache it returns "Not Found" otherwise it returns "Found". Case # created with Salesforce.com 14311948.
See code and output sample below:
VisualForce Page:
Controller:
Output:
See code and output sample below:
VisualForce Page:
<apex:page controller="CacheTestController" showChat="false" showHeader="false"> <div style="margin: 10px; font-size: 14px"> <pre id="put">In progress ...</pre> <pre id="get"></pre> </div> <script> Visualforce.remoting.Manager.invokeAction( 'CacheTestController.putCache', function(result, event) { document.getElementById('put').innerHTML = result; }, { escape: false } ); var tentative = 1; var timer = setInterval(function () { if (tentative == 100) clearInterval(timer); Visualforce.remoting.Manager.invokeAction( 'CacheTestController.getCache', tentative, function (result, event) { document.getElementById('get').innerHTML += result + '<br/>'; }, { escape: false } ); tentative++; }, 1000); </script> </apex:page>
Controller:
public class CacheTestController { private static final String PARTITION_NAME = 'FinancialServices'; private static final String KEY = 'STAGE'; private static final String VALUE = 'Any value'; @RemoteAction public static String putCache() { Cache.Partition partition = Cache.Session.getPartition(PARTITION_NAME); partition.put(KEY, VALUE); return 'ok'; } @RemoteAction public static String getCache(String tentative) { String found = 'Found: ' + tentative; Cache.Partition partition = Cache.Session.getPartition(PARTITION_NAME); String cacheValue = (String) partition.get(KEY); if (cacheValue == null) { found = 'Not Found: ' + tentative; } return found; } }
Output:
Found: 1 Found: 2 Found: 3 Found: 4 Found: 5 Found: 6 Found: 7 Found: 8 Found: 9 Found: 10 Found: 11 Found: 12 Found: 13 Found: 14 Found: 15 Not Found: 16 Found: 17 Found: 18 Found: 19 Found: 20 Found: 21 Found: 22 Not Found: 23 Found: 24 Found: 25 Found: 26 Found: 27 Found: 28 Not Found: 29 Not Found: 30 Found: 31 Found: 32 Found: 33 Found: 34 Found: 35 Found: 36 Found: 37 Found: 38 Found: 39 Found: 40 Found: 41 Found: 42 Found: 43 Not Found: 44 Found: 45 Not Found: 46 Found: 47 Found: 48 Found: 49 Found: 50 Found: 51 Found: 52 Found: 53 Found: 54 Not Found: 55 Found: 56 Found: 57 Found: 58 Found: 59 Found: 60 Found: 61 Found: 62 Found: 63 Not Found: 64 Found: 65 Found: 66 Found: 67 Found: 68 Found: 69 Found: 70 Found: 71 Found: 72 Not Found: 73 Found: 74 Found: 75 Found: 76 Found: 77 Not Found: 78 Found: 79 Found: 80 Found: 81 Found: 82 Found: 83 Not Found: 84 Found: 85 Found: 86 Found: 87 Found: 88 Found: 89 Found: 90 Found: 91 Found: 92 Found: 93 Found: 94 Found: 95 Not Found: 96 Found: 97 Found: 98 Found: 99 Found: 100
Here's an even simpler example--a unit test. It works in all our environments except our staging org.
Why on earth would that fail?