11use crate :: error:: Error ;
22use crate :: event:: Event ;
3- use crate :: fast_filters :: apply_filter_fast;
3+ use crate :: filters :: apply_filter_fast;
44use crate :: list_props:: { ListProps , Order , StartAfter } ;
55use crate :: prefetch:: { Prefetch , PrefetchExt } ;
6- use crate :: string_pool:: StringPool ;
76use indexmap:: IndexMap ;
87use std:: fmt:: Debug ;
98use std:: sync:: mpsc:: Sender ;
@@ -222,7 +221,6 @@ pub struct Cache {
222221 capacity : usize ,
223222 default_ttl : Option < Duration > ,
224223 sender : Option < Sender < Event > > ,
225- string_pool : StringPool ,
226224 #[ cfg( feature = "persist" ) ]
227225 persist_path : Option < std:: path:: PathBuf > ,
228226 _phantom : std:: marker:: PhantomData < Value > ,
@@ -254,7 +252,6 @@ impl Cache {
254252 capacity,
255253 default_ttl : None ,
256254 sender : None ,
257- string_pool : StringPool :: new ( ) ,
258255 #[ cfg( feature = "persist" ) ]
259256 persist_path : None ,
260257 _phantom : std:: marker:: PhantomData ,
@@ -285,7 +282,6 @@ impl Cache {
285282 capacity,
286283 default_ttl : None ,
287284 sender : Some ( sender) ,
288- string_pool : StringPool :: new ( ) ,
289285 #[ cfg( feature = "persist" ) ]
290286 persist_path : None ,
291287 _phantom : std:: marker:: PhantomData ,
@@ -312,7 +308,6 @@ impl Cache {
312308 capacity,
313309 default_ttl : Some ( default_ttl) ,
314310 sender : None ,
315- string_pool : StringPool :: new ( ) ,
316311 #[ cfg( feature = "persist" ) ]
317312 persist_path : None ,
318313 _phantom : std:: marker:: PhantomData ,
@@ -347,7 +342,6 @@ impl Cache {
347342 capacity,
348343 default_ttl : Some ( default_ttl) ,
349344 sender : Some ( sender) ,
350- string_pool : StringPool :: new ( ) ,
351345 #[ cfg( feature = "persist" ) ]
352346 persist_path : None ,
353347 _phantom : std:: marker:: PhantomData ,
@@ -693,42 +687,32 @@ impl Cache {
693687 /// ```
694688 pub fn insert < T , V > ( & mut self , key : T , value : V )
695689 where
696- T : Into < String > + Clone + AsRef < str > ,
690+ T : Into < String > ,
697691 V : ToValueBehavior ,
698692 {
699- let key_str = key. as_ref ( ) ;
700-
701- let interned_key = if key_str. len ( ) < 50 {
702- self . string_pool . get_or_intern ( key_str) . to_string ( )
703- } else {
704- key. into ( )
705- } ;
706-
707- if self . string_pool . len ( ) > 1000 {
708- self . string_pool . clear_if_large ( ) ;
709- }
693+ let key = key. into ( ) ;
710694
711695 let item = if let Some ( default_ttl) = self . default_ttl {
712696 CacheItem :: with_ttl ( value. to_value ( ) , default_ttl)
713697 } else {
714698 CacheItem :: new ( value. to_value ( ) )
715699 } ;
716700
717- if let Some ( existing_item) = self . map . get ( & interned_key ) {
701+ if let Some ( existing_item) = self . map . get ( & key ) {
718702 if existing_item. value == item. value {
719703 return ;
720704 }
721705 }
722706
723- if self . map . len ( ) >= self . capacity && !self . map . contains_key ( & interned_key ) {
707+ if self . map . len ( ) >= self . capacity && !self . map . contains_key ( & key ) {
724708 if let Some ( ( first_key, first_item) ) = self . map . shift_remove_index ( 0 ) {
725709 self . send_remove ( first_key, first_item. value ) ;
726710 }
727711 }
728712
729- self . map . insert ( interned_key . clone ( ) , item. clone ( ) ) ;
713+ self . map . insert ( key . clone ( ) , item. clone ( ) ) ;
730714
731- self . send_insert ( interned_key , item. value ) ;
715+ self . send_insert ( key , item. value ) ;
732716 }
733717
734718 /// Inserts a key-value pair with a specific TTL.
@@ -806,19 +790,11 @@ impl Cache {
806790 /// ```
807791 #[ inline]
808792 pub fn get ( & mut self , key : & str ) -> Option < & Value > {
809- let pooled_key = if key. len ( ) <= 50 {
810- Some ( self . string_pool . get_or_intern ( key) )
811- } else {
812- None
813- } ;
814-
815- let lookup_key = pooled_key. as_deref ( ) . unwrap_or ( key) ;
816-
817- if let Some ( ( _, item) ) = self . map . get_key_value ( lookup_key) {
793+ if let Some ( ( _, item) ) = self . map . get_key_value ( key) {
818794 item. prefetch_read ( ) ;
819795 }
820796
821- let is_expired = match self . map . get ( lookup_key ) {
797+ let is_expired = match self . map . get ( key ) {
822798 Some ( item) => {
823799 if let Some ( ttl) = item. ttl_millis {
824800 ( current_time_millis ( ) - item. created_at ) > ttl
@@ -830,12 +806,12 @@ impl Cache {
830806 } ;
831807
832808 if is_expired {
833- if let Some ( expired_item) = self . map . swap_remove ( lookup_key ) {
834- self . send_remove ( lookup_key . to_string ( ) , expired_item. value ) ;
809+ if let Some ( expired_item) = self . map . swap_remove ( key ) {
810+ self . send_remove ( key . to_string ( ) , expired_item. value ) ;
835811 }
836812 None
837813 } else {
838- self . map . get ( lookup_key ) . map ( |item| & item. value )
814+ self . map . get ( key ) . map ( |item| & item. value )
839815 }
840816 }
841817
@@ -874,16 +850,8 @@ impl Cache {
874850 }
875851
876852 pub fn remove ( & mut self , key : & str ) -> Result < ( ) , Error > {
877- let pooled_key = if key. len ( ) <= 50 {
878- Some ( self . string_pool . get_or_intern ( key) )
879- } else {
880- None
881- } ;
882-
883- let lookup_key = pooled_key. as_deref ( ) . unwrap_or ( key) ;
884-
885- if let Some ( item) = self . map . swap_remove ( lookup_key) {
886- self . send_remove ( lookup_key. to_string ( ) , item. value ) ;
853+ if let Some ( item) = self . map . swap_remove ( key) {
854+ self . send_remove ( key. to_string ( ) , item. value ) ;
887855 Ok ( ( ) )
888856 } else {
889857 Err ( Error :: KeyNotFound )
@@ -892,7 +860,6 @@ impl Cache {
892860
893861 pub fn clear ( & mut self ) {
894862 self . map . clear ( ) ;
895- self . string_pool . clear ( ) ;
896863 self . send_clear ( ) ;
897864 }
898865
0 commit comments