---
schema_version: "1"
id: 51b12bbd4239352e7aa16ccdb69d708145284b4c17bdd21bcbf8746dabe833aa
title: Cache Exceptions
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_cache_exceptions.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_cache_exceptions.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: ebe3b77b06086ba5c9d91ba6254fcc68a129defb0ce53fc02f9b96fdb60434e2
description: The Cache namespace contains exception classes.
---
# Cache Exceptions

The Cache namespace contains exception classes.

All exception classes support built-in methods for returning the error message and exception type. See [Exception Class and Built-In Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_exception_methods.htm "An exception denotes an error that disrupts the normal flow of code execution. You can use Apex built-in exceptions or create custom exceptions. All exceptions have common methods.") in the Apex Developer Guide.

The Cache namespace contains these exceptions.

<table class="featureTable sort_table" summary="">


          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader vertical-align-top " id="d1814804e67">Exception</th>

              <th class="featureTableHeader vertical-align-top " id="d1814804e70">Thrown when</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.Session.SessionCacheException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">An error occurred while adding or retrieving a value in the session cache.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.Session.SessionCacheNoSessionException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">An attempt is made to access the cache when the session cache isn’t available.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.Org.OrgCacheException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">An attempt is made to access a partition that doesn’t exist or whose name is
                invalid.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.InvalidParamException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">An invalid parameter value is passed into a method of <samp class="codeph apex_code">Cache.Session</samp> or <samp class="codeph apex_code">Cache.Org</samp>. This error
                occurs when:<ul class="ul bulletList">
                  <li class="li">The key referenced is null or empty or is not alphanumeric.</li>

                  <li class="li">The key isn’t qualified with the namespace and partition in the format <samp class="codeph apex_code">&lt;namespace&gt;.&lt;partition&gt;.&lt;key&gt;</samp>.</li>

                  <li class="li">The key isn’t qualified in the format <samp class="codeph apex_code">&lt;key&gt;</samp>
                    for the default partition, or for a key inserted through the partition object.</li>

                  <li class="li">The namespace referenced is null or empty.</li>

                  <li class="li">The partition name is null or empty or is not alphanumeric.</li>

                  <li class="li">Another referenced value is null.</li>

                </ul>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.ItemSizeLimitExceededException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when"><span class="ph" id="apex_cache_item_size_exception"><a name="apex_cache_item_size_exception"><!-- --></a>A cache <samp class="codeph apex_code">put</samp> call is made with an item that exceeds the maximum size limit. To fix this
                  error, break the item into multiple, smaller items.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph ">Cache.BulkApiKeysLimitExceededException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">The number of key parameters passed into a bulk method - <samp class="codeph ">get(keys)</samp> or <samp class="codeph ">contains(setOfKeys)</samp> exceeds the
                maximum limit of 10.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.PlatformCacheInvalidOperationException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">A cache <samp class="codeph apex_code">put</samp> or <samp class="codeph apex_code">remove</samp> call is made that is not allowed. For example, when calling <samp class="codeph apex_code">put</samp> or <samp class="codeph apex_code">remove</samp>
                inside a Visualforce constructor.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.CacheBuilderExecutionException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">This error occurs when the execution of the CacheBuilder fails; this could be due to
                an error in parsing, a permissions error while accessing records, or an issue with Apex
                callouts.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1814804e67" data-title="Exception"><samp class="codeph apex_code">Cache.InvalidCacheBuilderException</samp></td>

              <td class="entry" headers="d1814804e70" data-title="Thrown when">A <samp class="codeph apex_code">get(CacheBuilder cb, <span class="keyword">String</span> key)</samp>, <samp class="codeph apex_code">remove(CacheBuilder cb, <span class="keyword">String</span> key)</samp>, or <samp class="codeph apex_code">validateCacheBuilder(CacheBuilder cb)</samp> method is called but
                the <samp class="codeph apex_code">cb</samp> parameter is a class that does not implement
                the <samp class="codeph apex_code">Cache.CacheBuilder</samp> interface.</td>

            </tr>

          </tbody>

        </table>