(mut submit_rx: Receiver<CacheMeta>, pri_cache: ArcDiskCache<PathBuf, Status>)
| 697 | } |
| 698 | |
| 699 | fn cache_mgr(mut submit_rx: Receiver<CacheMeta>, pri_cache: ArcDiskCache<PathBuf, Status>) { |
| 700 | // Wait on the channel, and when we get something proceed from there. |
| 701 | while let Some(meta) = submit_rx.blocking_recv() { |
| 702 | info!( |
| 703 | "✨ Cache Manager Got -> {:?} {} {:?}", |
| 704 | meta.cache_key, meta.etime, meta.action |
| 705 | ); |
| 706 | |
| 707 | let CacheMeta { |
| 708 | cache_key, |
| 709 | etime, |
| 710 | action, |
| 711 | } = meta; |
| 712 | |
| 713 | // Req path sometimes has dup //, so we replace them. |
| 714 | // let req_path = req_path.replace("//", "/"); |
| 715 | |
| 716 | match action { |
| 717 | Action::Submit { file, headers, cls } => { |
| 718 | let expiry = cls.expiry(etime); |
| 719 | let key = cache_key.clone(); |
| 720 | |
| 721 | pri_cache.insert( |
| 722 | key, |
| 723 | Status { |
| 724 | cache_key, |
| 725 | headers, |
| 726 | expiry, |
| 727 | cls, |
| 728 | nxtime: None, |
| 729 | }, |
| 730 | file, |
| 731 | ) |
| 732 | } |
| 733 | Action::Update => pri_cache.update_userdata(&cache_key, |d: &mut Status| { |
| 734 | d.expiry = d.cls.expiry(etime); |
| 735 | if let Some(exp) = d.expiry.as_ref() { |
| 736 | debug!("⏰ expiry updated to soft {} hard {}", exp.0, exp.1); |
| 737 | } |
| 738 | }), |
| 739 | Action::NotFound { cls } => { |
| 740 | match pri_cache.new_tempfile() { |
| 741 | Some(file) => { |
| 742 | let key = cache_key.clone(); |
| 743 | |
| 744 | pri_cache.insert( |
| 745 | key, |
| 746 | Status { |
| 747 | cache_key, |
| 748 | headers: BTreeMap::default(), |
| 749 | expiry: None, |
| 750 | cls, |
| 751 | nxtime: Some(etime + time::Duration::minutes(1)), |
| 752 | }, |
| 753 | file, |
| 754 | ) |
| 755 | } |
| 756 | None => { |
no test coverage detected