@@ -735,8 +735,7 @@ PHP_APCU_API void apc_cache_clear(apc_cache_t* cache)
735
735
PHP_APCU_API void apc_cache_default_expunge (apc_cache_t * cache , size_t size )
736
736
{
737
737
time_t t ;
738
- size_t suitable = 0L ;
739
- size_t available = 0L ;
738
+ size_t i ;
740
739
741
740
if (!cache ) {
742
741
return ;
@@ -751,43 +750,38 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
751
750
return ;
752
751
}
753
752
754
- /* make suitable selection */
755
- suitable = (cache -> smart > 0L ) ? (size_t ) (cache -> smart * size ) : (size_t ) (cache -> sma -> size /2 );
756
-
757
753
/* gc */
758
754
apc_cache_wlocked_gc (cache );
759
755
760
- /* get available */
761
- available = apc_sma_get_avail_mem (cache -> sma );
762
-
763
756
/* check that expunge is necessary */
764
- if (available < suitable ) {
765
- size_t i ;
766
-
767
- /* look for junk */
768
- for (i = 0 ; i < cache -> nslots ; i ++ ) {
769
- apc_cache_entry_t * * entry = & cache -> slots [i ];
770
- while (* entry ) {
771
- if (apc_cache_entry_expired (cache , * entry , t )) {
772
- apc_cache_wlocked_remove_entry (cache , entry );
773
- continue ;
774
- }
757
+ if (cache -> smart > 0L && apc_sma_get_avail_mem (cache -> sma ) >= (size_t ) (cache -> smart * size )) {
758
+ apc_cache_wunlock (cache );
759
+ return ;
760
+ }
775
761
776
- /* grab next entry */
777
- entry = & (* entry )-> next ;
762
+ /* look for junk */
763
+ for (i = 0 ; i < cache -> nslots ; i ++ ) {
764
+ apc_cache_entry_t * * entry = & cache -> slots [i ];
765
+ while (* entry ) {
766
+ if (apc_cache_entry_expired (cache , * entry , t )) {
767
+ apc_cache_wlocked_remove_entry (cache , entry );
768
+ continue ;
778
769
}
779
- }
780
770
781
- /* if the cache now has space, then reset last key */
782
- if (apc_sma_get_avail_size (cache -> sma , size )) {
783
- /* wipe lastkey */
784
- memset (& cache -> header -> lastkey , 0 , sizeof (apc_cache_slam_key_t ));
785
- } else {
786
- /* with not enough space left in cache, we are forced to expunge */
787
- apc_cache_wlocked_real_expunge (cache );
771
+ /* grab next entry */
772
+ entry = & (* entry )-> next ;
788
773
}
789
774
}
790
775
776
+ /* if the cache now has space, then reset last key */
777
+ if (apc_sma_get_avail_size (cache -> sma , size )) {
778
+ /* wipe lastkey */
779
+ memset (& cache -> header -> lastkey , 0 , sizeof (apc_cache_slam_key_t ));
780
+ } else {
781
+ /* with not enough space left in cache, we are forced to expunge */
782
+ apc_cache_wlocked_real_expunge (cache );
783
+ }
784
+
791
785
apc_cache_wunlock (cache );
792
786
}
793
787
/* }}} */
0 commit comments