django-vcache 3.0.0__tar.gz → 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {django_vcache-3.0.0 → django_vcache-3.1.0}/Cargo.lock +3 -3
  2. {django_vcache-3.0.0 → django_vcache-3.1.0}/Cargo.toml +1 -1
  3. {django_vcache-3.0.0 → django_vcache-3.1.0}/PKG-INFO +1 -1
  4. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-pyo3/src/async_bridge.rs +70 -7
  5. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-pyo3/src/client.rs +2 -2
  6. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-pyo3/src/lib.rs +4 -0
  7. {django_vcache-3.0.0 → django_vcache-3.1.0}/pyproject.toml +1 -1
  8. {django_vcache-3.0.0 → django_vcache-3.1.0}/LICENSE +0 -0
  9. {django_vcache-3.0.0 → django_vcache-3.1.0}/README.md +0 -0
  10. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/Cargo.toml +0 -0
  11. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/examples/bench.rs +0 -0
  12. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/examples/standalone.rs +0 -0
  13. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/src/connection.rs +0 -0
  14. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/src/lib.rs +0 -0
  15. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/src/result.rs +0 -0
  16. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/src/runtime.rs +0 -0
  17. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-core/tests/runtime_provider.rs +0 -0
  18. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-pyo3/Cargo.toml +0 -0
  19. {django_vcache-3.0.0 → django_vcache-3.1.0}/crates/vcache-pyo3/src/completion.rs +0 -0
  20. {django_vcache-3.0.0 → django_vcache-3.1.0}/django_vcache/__init__.py +0 -0
  21. {django_vcache-3.0.0 → django_vcache-3.1.0}/django_vcache/backend.py +0 -0
  22. {django_vcache-3.0.0 → django_vcache-3.1.0}/django_vcache/exceptions.py +0 -0
@@ -725,7 +725,7 @@ dependencies = [
725
725
 
726
726
  [[package]]
727
727
  name = "rlib-link-test"
728
- version = "3.0.0"
728
+ version = "3.1.0"
729
729
  dependencies = [
730
730
  "pyo3",
731
731
  "vcache-pyo3",
@@ -1005,7 +1005,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
1005
1005
 
1006
1006
  [[package]]
1007
1007
  name = "vcache-core"
1008
- version = "3.0.0"
1008
+ version = "3.1.0"
1009
1009
  dependencies = [
1010
1010
  "redis",
1011
1011
  "rustls",
@@ -1014,7 +1014,7 @@ dependencies = [
1014
1014
 
1015
1015
  [[package]]
1016
1016
  name = "vcache-pyo3"
1017
- version = "3.0.0"
1017
+ version = "3.1.0"
1018
1018
  dependencies = [
1019
1019
  "pyo3",
1020
1020
  "redis",
@@ -3,7 +3,7 @@ resolver = "2"
3
3
  members = ["crates/vcache-core", "crates/vcache-pyo3"]
4
4
 
5
5
  [workspace.package]
6
- version = "3.0.0"
6
+ version = "3.1.0"
7
7
  edition = "2024"
8
8
 
9
9
  [workspace.dependencies]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-vcache
3
- Version: 3.0.0
3
+ Version: 3.1.0
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Framework :: Django
6
6
  Classifier: Framework :: Django :: 5.0
@@ -77,6 +77,38 @@ pub fn raw_result_into_py(raw: RawResult, py: Python<'_>) -> Result<Py<PyAny>, P
77
77
  }
78
78
  }
79
79
 
80
+ /// Closure that materializes a Python value on the event-loop thread
81
+ /// (GIL held) — the payload of [`BridgeValue::Custom`].
82
+ ///
83
+ /// Constraint: must not capture Python objects. The closure is not
84
+ /// reachable from `__traverse__`, so a captured `Py<...>` would be
85
+ /// invisible to the cyclic GC; build Python values only inside the call.
86
+ pub type ProduceValue = Box<dyn FnOnce(Python<'_>) -> PyResult<Py<PyAny>> + Send>;
87
+
88
+ /// Payload the op task sends through the oneshot channel.
89
+ ///
90
+ /// `Raw` is the driver's own result enum. `Custom` lets rlib consumers
91
+ /// (e.g. gt_rust's ingest pipeline) route arbitrary results through this
92
+ /// same awaitable — busy-yield, completion pipe, cancel-abort and GC
93
+ /// support included — instead of hand-rolling their own Future protocol.
94
+ pub enum BridgeValue {
95
+ Raw(RawResult),
96
+ Custom(ProduceValue),
97
+ }
98
+
99
+ impl From<RawResult> for BridgeValue {
100
+ fn from(raw: RawResult) -> Self {
101
+ BridgeValue::Raw(raw)
102
+ }
103
+ }
104
+
105
+ fn bridge_value_into_py(value: BridgeValue, py: Python<'_>) -> Result<Py<PyAny>, PyErr> {
106
+ match value {
107
+ BridgeValue::Raw(raw) => raw_result_into_py(raw, py),
108
+ BridgeValue::Custom(produce) => produce(py),
109
+ }
110
+ }
111
+
80
112
  // =========================================================================
81
113
  // RustAwaitable — deferred-callback async bridge
82
114
  //
@@ -116,7 +148,7 @@ struct DoneCallback {
116
148
  struct CallbackState {
117
149
  event_loop: Py<PyAny>,
118
150
  callbacks: Vec<DoneCallback>,
119
- result_slot: Arc<Mutex<Option<Result<RawResult, ()>>>>,
151
+ result_slot: Arc<Mutex<Option<Result<BridgeValue, ()>>>>,
120
152
  /// Completion-pipe registration, removed on cancel so the strong
121
153
  /// reference the registry holds doesn't outlive the awaitable's use.
122
154
  pipe: Arc<LoopPipe>,
@@ -134,7 +166,7 @@ const MISS_STREAK_THRESHOLD: u8 = 8;
134
166
 
135
167
  #[pyclass]
136
168
  pub struct RustAwaitable {
137
- rx: Option<oneshot::Receiver<RawResult>>,
169
+ rx: Option<oneshot::Receiver<BridgeValue>>,
138
170
  /// Successful result value — stored for result() after StopIteration delivery.
139
171
  value: Option<Py<PyAny>>,
140
172
  /// Error exception object — raised by result() for the Task to propagate.
@@ -318,7 +350,7 @@ impl RustAwaitable {
318
350
  if let Some(raw_result) = maybe {
319
351
  this.cb = None;
320
352
  return match raw_result {
321
- Ok(raw) => match raw_result_into_py(raw, py) {
353
+ Ok(raw) => match bridge_value_into_py(raw, py) {
322
354
  Ok(val) => deliver_value(&mut this, py, val),
323
355
  Err(e) => deliver_error(&mut this, py, e),
324
356
  },
@@ -347,7 +379,7 @@ impl RustAwaitable {
347
379
  hint.store(0, std::sync::atomic::Ordering::Relaxed);
348
380
  }
349
381
  let pending = std::mem::take(&mut this.pending_callbacks);
350
- let result = match raw_result_into_py(raw, py) {
382
+ let result = match bridge_value_into_py(raw, py) {
351
383
  Ok(val) => deliver_value(&mut this, py, val),
352
384
  Err(e) => deliver_error(&mut this, py, e),
353
385
  };
@@ -550,12 +582,12 @@ impl RustAwaitable {
550
582
  }
551
583
 
552
584
  impl RustAwaitable {
553
- pub fn new(rx: oneshot::Receiver<RawResult>) -> Self {
585
+ pub fn new(rx: oneshot::Receiver<BridgeValue>) -> Self {
554
586
  Self::new_with_hint(rx, None)
555
587
  }
556
588
 
557
589
  pub fn new_with_hint(
558
- rx: oneshot::Receiver<RawResult>,
590
+ rx: oneshot::Receiver<BridgeValue>,
559
591
  hint: Option<Arc<std::sync::atomic::AtomicU8>>,
560
592
  ) -> Self {
561
593
  use std::sync::atomic::Ordering;
@@ -604,7 +636,7 @@ impl RustAwaitable {
604
636
  };
605
637
  let maybe = cb.result_slot.lock().unwrap().take();
606
638
  match maybe {
607
- Some(Ok(raw)) => match raw_result_into_py(raw, py) {
639
+ Some(Ok(raw)) => match bridge_value_into_py(raw, py) {
608
640
  Ok(val) => {
609
641
  this.resolved = true;
610
642
  this.value = Some(val);
@@ -641,3 +673,34 @@ impl RustAwaitable {
641
673
  }
642
674
  }
643
675
  }
676
+
677
+ /// Test-only: an awaitable resolving to `value` through the
678
+ /// [`BridgeValue::Custom`] path after `delay_ms`. The Raw path is covered
679
+ /// by every driver op; this is the only in-tree producer of Custom, which
680
+ /// otherwise exists for rlib consumers. `delay_ms=0` exercises the
681
+ /// busy-yield fast path, larger delays the completion pipe; `error=True`
682
+ /// delivers a ValueError through the closure instead.
683
+ #[pyfunction]
684
+ #[pyo3(signature = (value, delay_ms = 0, error = false))]
685
+ pub fn _testing_custom_awaitable(
686
+ py: Python<'_>,
687
+ value: String,
688
+ delay_ms: u64,
689
+ error: bool,
690
+ ) -> PyResult<Py<PyAny>> {
691
+ let (tx, rx) = oneshot::channel();
692
+ let mut awaitable = RustAwaitable::new(rx);
693
+ let handle = get_runtime().spawn(async move {
694
+ if delay_ms > 0 {
695
+ tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
696
+ }
697
+ let produce: ProduceValue = if error {
698
+ Box::new(move |_py| Err(pyo3::exceptions::PyValueError::new_err(value)))
699
+ } else {
700
+ Box::new(move |py| Ok(PyString::new(py, &value).into_any().unbind()))
701
+ };
702
+ let _ = tx.send(BridgeValue::Custom(produce));
703
+ });
704
+ awaitable.set_abort_handle(handle.abort_handle());
705
+ Ok(awaitable.into_pyobject(py)?.into_any().unbind())
706
+ }
@@ -3,7 +3,7 @@ use pyo3::types::PyBytes;
3
3
  use std::sync::atomic::AtomicU8;
4
4
  use std::sync::Arc;
5
5
 
6
- use crate::async_bridge::{raw_result_into_py, RustAwaitable};
6
+ use crate::async_bridge::{raw_result_into_py, BridgeValue, RustAwaitable};
7
7
  use vcache_core::connection::{
8
8
  connect_cluster, connect_sentinel, connect_standard, ClientCacheOpts, MasterAuth, TlsOpts,
9
9
  ValkeyConn,
@@ -51,7 +51,7 @@ macro_rules! async_op_inner {
51
51
  let mut $conn = $self.connection.clone();
52
52
  let handle = get_runtime().spawn(async move {
53
53
  let result: RawResult = async { $body }.await;
54
- let _ = tx.send(result);
54
+ let _ = tx.send(BridgeValue::Raw(result));
55
55
  });
56
56
  awaitable.set_abort_handle(handle.abort_handle());
57
57
  Ok(awaitable.into_pyobject($py)?.into_any().unbind())
@@ -28,5 +28,9 @@ fn _driver(m: &Bound<'_, PyModule>) -> PyResult<()> {
28
28
  install_crypto_provider();
29
29
  m.add_class::<RustValkeyDriver>()?;
30
30
  m.add_class::<RustAwaitable>()?;
31
+ m.add_function(pyo3::wrap_pyfunction!(
32
+ async_bridge::_testing_custom_awaitable,
33
+ m
34
+ )?)?;
31
35
  Ok(())
32
36
  }
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "django-vcache"
7
- version = "3.0.0"
7
+ version = "3.1.0"
8
8
  description = "A specialized, lightweight Django cache backend for Valkey."
9
9
  readme = "README.md"
10
10
  authors = [{ name = "David Burke", email = "david@burkesoftware.com" }]
File without changes
File without changes