Skip to content

Add register flag for Store instantiation  #547

@gpauloski

Description

@gpauloski

Describe the Request

The docs frequently suggest the following pattern:

store = Store('my-store', ...)
register_store(store)

We can change this to an easier one-liner by adding a register flag to Store.

store = Store('my-store', ..., register=True)

In this case, Store can become a singleton type, returning an existing instance if one with a matching name exists and otherwise instantiating a new one and registering it. By default, register=False preserving all prior functionality and skipping the singleton factory.

This opt-in singleton pattern would help prevent users from instantiating the same Store by accident multiple times in the same process, negating the cache/connector persistence benefits.

This might also require some other changes/considerations:

Sample Code

No response

Metadata

Metadata

Assignees

Labels

enhancementNew features or improvements to existing functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions