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
Copy file name to clipboardExpand all lines: README.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -407,6 +407,7 @@ A durable, fixed-size circular buffer (or queue) that stores the last N items. W
407
407
- Managing data streams where only the most recent information is relevant.
408
408
409
409
#### Key Concepts
410
+
410
411
-**Initial Capacity:** Upon its initial creation, a ring buffer has a default capacity of **1**. You must explicitly call `SetCapacity(int)` to configure it to your desired size.
411
412
412
413
-**Ordering & Overwriting:** The buffer behaves like a standard queue, so **FIFO**. Its unique feature is that enqueuing an item into a full buffer succeeds by removing the **oldest** item to make space.
@@ -445,43 +446,42 @@ A one-to-many collection that maps a key to an independent `IDurableRingBuffer<T
445
446
**Useful for:**
446
447
447
448
- Tracking the last N events _per-user_ or _per-device_.
448
-
- Managing recent activity feeds for multiple entities (e.g., last 10 comments on multiple blog posts).
449
+
- Managing recent activity feeds for multiple entities (*e.g., last 10 comments on multiple blog posts*).
-**Initial Capacity:** The `capacity` parameter in `GetOrCreate(key, capacity)` is **only** used when a buffer for that `key` is being created for the first time. On subsequent calls for an existing buffer, this parameter is ignored, preserving the buffer's current capacity.
454
-
455
-
-**Implicit Creation:** Buffers are created automatically the first time a key is accessed via `GetOrCreate(key, capacity)`. You don't need to check if a buffer exists before using it (*although you can*).
454
+
-**Implicit Creation**: Buffers are created automatically the first time a key is accessed via `EnsureBuffer(key, capacity)`. You don't need to check if a buffer exists before using it (*although you can*).
456
455
456
+
-**Ensured Capacity**: The capacity parameter in *EnsureBuffer(key, capacity)* is always enforced. When a buffer is created for the first time, it is set with this capacity. If a buffer for that key already exists, its capacity will be overwritten with the new value, which may result in data loss if the new capacity is smaller and the buffer had more items than the new capacity!
457
457
458
-
-**Isolation:**Each ring buffer in the collection is completely independent. Operations on one buffer (like `Enqueue` or `SetCapacity`) have no effect on any other buffer.
458
+
-**Isolation**: Each ring buffer in the collection is completely independent. Operations on one buffer have no effect on any other buffer.
459
459
460
-
-**Fine-Grained Durability:** This component is optimized for performance. An operation on a single buffer results in a small, specific logentry, rather than re-serializing an entire dictionary of buffers.
460
+
-**Fine-Grained Persistence**: Any operation on a single buffer results in a small, specific log-entry, rather than re-serializing all buffers.
461
461
462
462
```csharp
463
-
// Get a buffer for "user1".
463
+
// Get a buffer for "user1".
464
464
// Since it's new, it will be created with a capacity of 10.
465
465
466
-
varbuffer1=collection.GetOrCreate("user1", 10);
466
+
varbuffer1=collection.EnsureBuffer("user1", 10);
467
467
buffer1.Enqueue("Logged In");
468
468
buffer1.Enqueue("Viewed Dashboard");
469
469
470
470
// Get a buffer for another user. It is isolated from the above!
471
-
varbuffer2=collection.GetOrCreate("user2", 5);
471
+
varbuffer2=collection.EnsureBuffer("user2", 5);
472
472
buffer2.Enqueue("Viewed Product Page");
473
473
474
-
// Because the buffer for "user1" already exists,
475
-
// the capacity parameter (15) is ignored here,
476
-
// and its current capacity (10) is preserved. The same
477
-
// buffer instance is also returned!
474
+
// Because the buffer for "user1" already exists, calling EnsureBuffer
475
+
// again will overwrite its capacity from 10 to 15.
0 commit comments