Just started trying out Platform Cache, and the code needs to work with or without cache partitions set up.

As the first error I got was:

SessionCacheException:[]: A default partition was not found. To cache without partition reference, designate a partition as default.

the first thought to achieve the with/without is this:

        EventType[] ets;
        try {
            ets = (EventType[]) Cache.Session.get(EventTypesCache.class, 'N/A');
        } catch (Cache.Session.SessionCacheException e) {
            // Load data locally
            ets = ...

But is there a cleaner way to do this?

1 Answer 1


According to documentation here it says if the default partition is not there it will throw Cache.Session.SessionCacheException and seems that how you are planning to handle the exception right now and seems like the way to go

If no default partition is specified in the org, calling a cache method without fully qualifying the key name causes a ​Cache.Session.SessionCacheException to be thrown.

  • Thanks. I looked around the documentation but didn't find an isCacheAvailable method or a method that looked like it e.g. returned null but thought I might be missing something.
    – Keith C
    May 11, 2019 at 9:59
  • @KeithC - I also went through its parent Partition class and it did have a method (validatePartitionName) but its returned null so left it there thinking there isnt anything avaliable for now. One another option is to use custom setting or metadata to check for existence of platform cache. Needs a bit of admin work though to maintain that
    – RedDevil
    May 11, 2019 at 14:29
  • Thanks. Looks like handling the exception is the way to go for now.
    – Keith C
    May 11, 2019 at 15:19
  • That's not great. Handling program flow via exceptions really isn't a good look.
    – dyson
    Apr 29, 2020 at 18:59

You must log in to answer this question.

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