You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// GetEntitiesMemoized retrieves entities based on the provided filter `f`, using a concurrent-safe cache to optimize performance.
237
+
//
238
+
// ## Cache Behavior:
239
+
// - **Cache Hit**: If the requested entities are found in the `cache`, the function returns the cached result immediately, avoiding a redundant query.
240
+
// - **Cache Miss**: If the requested entities are *not* found in the cache, the function fetches them from the registry using `rm.GetEntities(f)`,
241
+
// stores the result in the `cache`, and returns the newly retrieved entities.
242
+
//
243
+
// ## Concurrency and Thread Safety:
244
+
// - The `cache` is implemented using `sync.Map`, ensuring **safe concurrent access** across multiple goroutines.
245
+
// - `sync.Map` is optimized for scenarios where **reads significantly outnumber writes**, making it well-suited for caching use cases.
246
+
//
247
+
// ## Ownership and Responsibility:
248
+
// - **RegistryManager (`rm`)**: Owns the logic for retrieving entities from the source when a cache miss occurs.
249
+
// - **Caller Ownership of Cache**: The caller is responsible for providing and managing the `cache` instance.
250
+
// This function does *not* handle cache eviction, expiration, or memory constraints—those concerns must be managed externally.
251
+
//
252
+
// ## Parameters:
253
+
// - `f entity.Filter`: The filter criteria used to retrieve entities.
254
+
// - `cache *RegistryEntityCache`: A pointer to a concurrent-safe cache (`sync.Map`) that stores previously retrieved entity results.
255
+
//
256
+
// ## Returns:
257
+
// - `[]entity.Entity`: The list of retrieved entities (either from cache or freshly fetched).
258
+
// - `int64`: The total count of entities matching the filter.
259
+
// - `int`: The number of unique entities found.
260
+
// - `error`: An error if the retrieval operation fails.
0 commit comments