From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id AF37389D7 for ; Tue, 22 Aug 2023 14:02:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8BB3FC5EF for ; Tue, 22 Aug 2023 14:01:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 22 Aug 2023 14:01:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CF6C9432E3 for ; Tue, 22 Aug 2023 14:01:54 +0200 (CEST) Date: Tue, 22 Aug 2023 14:01:54 +0200 From: Wolfgang Bumiller To: Lukas Wagner Cc: Max Carrara , Proxmox VE development discussion Message-ID: References: <20230821134444.620021-1-l.wagner@proxmox.com> <20230821134444.620021-5-l.wagner@proxmox.com> <8aaefb26-be4b-477c-b6a7-9e2fbe598215@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8aaefb26-be4b-477c-b6a7-9e2fbe598215@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.103 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [RFC proxmox 4/7] cache: add new crate 'proxmox-cache' X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2023 12:02:25 -0000 On Tue, Aug 22, 2023 at 01:33:44PM +0200, Lukas Wagner wrote: (...) > > ... can be replaced as follows, in order to make it similar to > > std::collections::{HashMap, BTreeMap}: > > > > impl> for SharedCache { > > // Returns old value on successful insert, if given > > fn insert(&self, k: K, v: Value) -> Result, Error> { > > // ... > > } > > > > fn get(&self, k: K) -> Result, Error> { > > // ... > > } > > > > fn remove(&self, k: K) -> Result, Error> { > > // ... > > } > > } > > > > If necessary / sensible, other methods (inspired by {HashMap, BTreeMap} can > > be added as well, such as remove_entry, retain, clear, etc. > > > > I don't have any hard feelings regarding the naming, but not returning a > Value from `delete` was a conscious decision - we simply don't need it right > now. I don't want to deserialize to just throw away the value. > Also, reading *and* deleting at the same time *might* introduce the need for > file locking - although I'm not completely sure about that yet. > > If we ever need a `remove` that also returns the value, we could just > introduce a second method, e.g. `take`. Locking might make sense though. If we want to refresh data, it may make sense to first lock the cache entry, then re-check the expiration time, and only then do the actual refresh. That way, 5 concurrent accesses will cause only a single refresh, since afterwards they all see the new value. As for `take` vs locking: You *could* have the first operation be a `rename` to a random string, then open,delete,read (but then you need something that cleans up after left-overs when a process gets killed between the rename & delete. But I don't quite see the value in this functionality here for now :-)