DataStore interface

Objects implementing the DataStore interface represent stores for small amounts of arbitrary data attached to other objects, such as SecurityPrincipal and Plugin. This is usually accessed through a data property.

This is only suitable for data which does not change often, for example, configuration or rarely changing values.

Limitations

Keys

Only strings are supported as keys. Some uses of DataStore objects impose extra requirements, such as the requirement to use a prefix with the plugin name.

Values

Only values which can be serialised to JSON can be stored.

Capacity

There is a low limit on the amount of data which can be stored. The JSON serialisation should ideally be less than 1024 bytes.

Race conditions

Because of the underlying implementation, there is a potential race condition which means this is not suitable for concurrent writes.

  • All the data is stored as one blob in the underlying storage.
  • When the store is first accessed (read or write), all the data is loaded from the storage.
  • When a value is written, all the data is written back to storage.
  • The store is discarded at the end of the request.

This means that if there are two concurrent requests which write different values in the data store, one of those values can be lost if the timing is unlucky.

This is a deliberate design decision to enable the platform to be implemented efficiently. If this is unacceptable for your plugin, use the database interface instead.

Interface

DataStore objects implement the standard JavaScript Object interface for key/value data using the [] operator.

Only strings are allowed as keys.