Skip to content

Commit 850c32f

Browse files
Update README.md
1 parent 69fb14a commit 850c32f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ A durable, fixed-size circular buffer (or queue) that stores the last N items. W
407407
- Managing data streams where only the most recent information is relevant.
408408

409409
#### Key Concepts
410+
410411
- **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.
411412

412413
- **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
445446
**Useful for:**
446447

447448
- 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*).
449450
- Storing recent log messages partitioned _by category_.
450451

451452
#### Key Concepts
452453

453-
- **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*).
456455

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!
457457

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.
459459

460-
- **Fine-Grained Durability:** This component is optimized for performance. An operation on a single buffer results in a small, specific log entry, 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.
461461

462462
```csharp
463-
// Get a buffer for "user1".
463+
// Get a buffer for "user1".
464464
// Since it's new, it will be created with a capacity of 10.
465465
466-
var buffer1 = collection.GetOrCreate("user1", 10);
466+
var buffer1 = collection.EnsureBuffer("user1", 10);
467467
buffer1.Enqueue("Logged In");
468468
buffer1.Enqueue("Viewed Dashboard");
469469

470470
// Get a buffer for another user. It is isolated from the above!
471-
var buffer2 = collection.GetOrCreate("user2", 5);
471+
var buffer2 = collection.EnsureBuffer("user2", 5);
472472
buffer2.Enqueue("Viewed Product Page");
473473

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.
476+
// The same buffer instance is returned.
478477
479-
var buffer3 = collection.GetOrCreate("user1", 15);
478+
var buffer3 = collection.EnsureBuffer("user1", 15);
480479
Console.WriteLine(ReferenceEquals(buffer1, buffer3)); // True
481-
Console.WriteLine(buffer3.Capacity == 10); // True
480+
Console.WriteLine(buffer1.Capacity == 15); // True
481+
Console.WriteLine(buffer3.Capacity == 15); // True
482482
buffer3.Enqueue("Updated Profile");
483483

484-
// Durably store all changes in one go!
484+
// Atomically persist all changes!
485485
await WriteStateAsync();
486486
```
487487

0 commit comments

Comments
 (0)