1

Let's say I have the following method getMyString() in my Apex Controller.

I would like to refresh this SOQL query once in 30 minutes. Would it be possible to store the data in a 'local storage' type of way?

Example Pseudo Solution

if( LocalServerStorage.get( 'lastStoredDate' ) != new Date() )
{
    String myString = [ /* .. SOQL .. */ ];

    LocalServerStorage.store( 'myString', myString );
    LocalServerStorage.store( 'lastStoredDate', new Date() );
}
else
    String myString = LocalServerStorage.get( 'myString' );

Sample SOQL code

public static String getMyString()
{
    return [
        SELECT 
            MyString__c
        FROM 
            Strings__c
        WHERE
            Key = 'My String'
        WITH
            SECURITY_ENFORCED
        LIMIT 1
    ];
}

1 Answer 1

3

The thing you're looking for is probably the The Org (platform) Cache (as opposed to the Session Cache).

There's also a relevant trailhead module to help get you started.

In a nutshell:

  • You create a cache partition through the setup menu
  • You call .getPartition() to retrieve it in code
  • And you use that partition to .put() and .get() data

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .