Show TOC

Storing Module Runtime DataLocate this document in the navigation structure

Use

The module storage service enables you to store and retrieve the runtime data of a module instance. This service provides significant benefits in terms of performance and maintenance compared to storing data in the iView properties in Portal Content Directory (PCD).

When a module is removed from a workspace page, its storage is removed automatically. During workspace transport, the storage of each module in the workspace is included in the transport package.

Package

The relevant APIs are contained in the com.sap.workspaces.module.storage package.

Development Guidelines

The following guidelines help you to decide when and how to use this storage.

Data Size and Format

  • You can use module storage for storing small amounts of either string or binary data, below 50KB per module on the average.

  • The data is stored as a collection of properties (keys and values). Both the number of keys and their size have an impact on performance, so do not use more than 100 keys.

  • Although module storage supports binary format, do not use it to store large binary files, but rather hashed keys or other binary snippets.

  • For large amounts of data, use external storage, such as a database or file system. In this case, you can use module storage for the keys of externally stored data.

  • To keep your external data storage in sync with the module instance, implement the module lifecycle event handling. To transport the external data along with the workspace, implement the transport event handling.

    For more information, see Responding to Events.

Read/Write operations

  • In an HTTP session, the IModuleStorageFactory.getStorage method loads the module data to an IModuleStorage object. If you are frequently accessing the module data, using this object is more efficient than calling the getStorage method each time you need the data.

  • Since writing to module storage creates only a small overhead, it can be reasonably frequent, such as saving the contents of a Text Pad module each time the user chooses to save.

Example

The following example illustrates how to access and use module storage:

private void storeModuleRuntimeContent(IPortalComponentRequest request)
{
// Get module storage
IWorkspacesRuntime workspacesRuntime = RuntimeFactory.getWorkspacesRuntime();
IModuleStorageFactory storageFactory = (IModuleStorageFactory) workspacesRuntime.getService(IModuleStorageFactory.class);
IModuleContext moduleContext = ModuleHelper.getModuleContext(request);
IModuleStorage storage = storageFactory.getStorage(moduleContext);

// Get string content
String value = storage.getProperty("key");

// Store string content
storage.setProperty("key", "value");}

// Store binary property
byte[] myBinaryData = "myBinaryData".getBytes();
InputStream binaryValue = new ByteArrayInputStream(myBinaryData);
storage.setBinaryProperty("key", binaryValue);