The Key Behavior Cache settings, pipelines, and methods

Last updated Friday, January 29, 2016 in Sitecore Experience Platform for Developer

The Key Behavior Cache stores information in the Experience Database (xDB) about a contact's recent activities across all channels in the content delivery environment. The cache is the part of the contact entity that is stored in the shared session state and is read-only.

At the end of an interaction, the Key Behavior Cache is automatically updated to include information about most marketing activities, such as goals triggered, outcomes achieved or campaigns interacted with. Although custom values can be stored in the Key Behavior Cache, these values do not update automatically and require a custom developer solution that must be implemented by the organization.

The Key Behavior Cache cannot be updated by an organization during content delivery. It can only be updated by running the UpdateKeyBehaviorCache pipeline. This pipeline is called from the CommitSession pipeline after the session has been submitted.

All Key Behavior Cache data is stored in the Key Behavior Cache collection in xDB. This is partitioned by the contact ID.

Settings

You can customize the following Key Behavior Cache settings in the Sitecore.Xdb.Config file:

Setting

Description

Xdb.Tracking.KeyBehaviorCache.MaximumCacheEntryCount

Specifies the maximum number of items in the cache for a given category, such as goals, page events, and so on.

The default value is 50 entries.

Xdb.Tracking.KeyBehaviorCache.MaximumInteractionPeriod

Specifies the maximum period for interactions that xDB uses during cache rebuilds or updates.

The default value is 30 days.

Xdb.Tracking.KeyBehaviorCache.MaximumInteractionCount

Specifies the maximum number of interactions that xDB examines during cache rebuilds or updates.

The default value is 25 interactions.

xDB.Enabled

Must be set to true for the Key Behavior Cache to work.

These settings are enabled by default if you have a valid xDB license.

The Key Behavior Cache pipelines

You can use the following pipelines to extend the Key Behavior Cache:

Pipeline

Description

UpdateKeyBehaviorCache

This pipeline performs updates with the latest cached items from the current interaction.

You can also use these processors to extend existing cache logic or update it with your own:

  • Sitecore.Analytics.Pipelines.UpdateKeyBehaviorCache.UpdateCustomValuesModelData to store custom interaction values.
  • Sitecore.Analytics.Pipelines.UpdateKeyBehaviorCache.UpdateKeyBehaviorCacheProcessor abstract class to use your own logic to add values

EnsureSessionContext

Executing this pipeline loads the Key Behavior Cache data.

CommitSession

Executing this pipeline saves the Key Behavior Cache data.

The Key Behavior Cache methods

The Key Behavior Cache-related methods enable you to extend the Sitecore.Analytics.Tracking.Contact functionality:

Method

Description

Sitecore.Analytics.Tracking.ContactKeyBehaviorCacheExtension.GetKeyBehaviorCache()

Retrieves read-only cache data.

You can use these methods, for example, to implement some personalization conditions based on information from the Key Behavior Cache.

Sitecore.Analytics.Tracking.ContactKeyBehaviorCacheExtension.LoadKeyBehaviorCache()

Loads the Key Behavior Cache for individual contacts.

You can use this to implement personalization for a contact who does not have a current session, then use that information to put them in relevant engagement plan states, for example.