Internal stream processor for SuperCache buffer queues.
This module bridges the internal message-passing queue (SuperCache.Internal.Queue)
with the caching layer (SuperCache). It creates a Stream that continuously
pulls items from a named queue and flushes each drained batch into the cache
via SuperCache.put_batch!/1.
Design
The stream is built using Stream.resource/3:
- Accumulator - The queue name/atom passed to
create/1. - Next function - Calls
Queue.get/1to fetch a batch of items. - Cleanup function - No-op, as the queue lifecycle is managed externally.
Queue.get/1 returns items in FIFO order, so sequential updates to the same
key within one batch preserve the last write. The batch is flushed with a
single put_batch!/1 call. If a batch contains a malformed tuple, the flush
retries item by item so valid tuples still land and only the bad item is
logged.
Warning
This is an internal module. Do not use it directly in application code.
Use SuperCache.Buffer or SuperCache.lazy_put/1 instead.
Summary
Types
Queue name or PID used as the stream accumulator.
Types
Functions
@spec create(queue_ref()) :: Enumerable.t()
Creates a Stream that continuously pulls items from the given queue.
The stream yields batches of items returned by Queue.get/1.
When the queue process is no longer running, the stream halts cleanly
(the buffer runner decides whether to restart it).
Examples
stream = SuperCache.Internal.Stream.create(:my_buffer)
Stream.take(stream, 10) |> Enum.to_list()
@spec make_stream_pipe(Enumerable.t()) :: :ok
Consumes an enumerable and pushes each batch into the cache.
Runs the stream to completion. Drained batches are written with
SuperCache.put_batch!/1; if a batch contains a malformed tuple, the
batch is retried item by item so valid tuples still land and only the bad
item is logged.
@spec push(tuple()) :: :ok
Pushes a single item into the SuperCache.
Wraps SuperCache.put/1 with error handling. If the put fails, the error
is logged but not raised, ensuring the stream continues processing.
Examples
SuperCache.Internal.Stream.push({:user, 1, "Alice"})
# => :ok