Class InMemoryStickyBucketServiceImpl
java.lang.Object
growthbook.sdk.java.stickyBucketing.InMemoryStickyBucketServiceImpl
- All Implemented Interfaces:
StickyBucketService
For simple bucket persistence using the in memory's storage(Map) (can be polyfilled for other environments)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newInMemoryStickyBucketServiceImplbacked by a thread-safe map, suitable for use withGrowthBookClientwhere evaluations run concurrently.InMemoryStickyBucketServiceImpl(Map<String, StickyAssignmentsDocument> localStorage) Constructs a newInMemoryStickyBucketServiceImplwith the specified local storage. -
Method Summary
Modifier and TypeMethodDescriptiongetAllAssignments(Map<String, String> attributes) Method for getting sticky bucket assignments from cache (in memory: hashmap) by attributes of contextgetAssignments(String attributeName, String attributeValue) Method for getting all assignments document from cache (in memory: hashmap)voidMethod for saving assignments document to cache (in memory: hashmap)
-
Constructor Details
-
InMemoryStickyBucketServiceImpl
public InMemoryStickyBucketServiceImpl()Constructs a newInMemoryStickyBucketServiceImplbacked by a thread-safe map, suitable for use withGrowthBookClientwhere evaluations run concurrently. -
InMemoryStickyBucketServiceImpl
Constructs a newInMemoryStickyBucketServiceImplwith the specified local storage.- Parameters:
localStorage- a map to store sticky assignments documents in memory. The map is used directly as the backing storage, so assignments saved by this service are visible to the caller and vice versa. A plain map (e.g.HashMap) is only safe when the service is used from a single thread; pass a thread-safeConcurrentMap(e.g.ConcurrentHashMap) when the service is shared by aGrowthBookClientevaluating on multiple threads. Anullmap falls back to an emptyConcurrentHashMap.
-
-
Method Details
-
getAssignments
Method for getting all assignments document from cache (in memory: hashmap)- Specified by:
getAssignmentsin interfaceStickyBucketService- Parameters:
attributeName- attributeName with attributeValue together present a key that us for find proper StickyAssignmentsDocumentattributeValue- attributeName with attributeValue together present a key that us for find proper StickyAssignmentsDocument- Returns:
- StickyAssignmentsDocument
-
saveAssignments
Method for saving assignments document to cache (in memory: hashmap)- Specified by:
saveAssignmentsin interfaceStickyBucketService- Parameters:
doc- StickyAssignmentsDocument
-
getAllAssignments
Method for getting sticky bucket assignments from cache (in memory: hashmap) by attributes of context- Specified by:
getAllAssignmentsin interfaceStickyBucketService- Parameters:
attributes- Map of String key and String value that you have in GBContext- Returns:
- Map with key String and value StickyAssignmentsDocument
-