Commit 7bf9a96
committed
fix: enforce LRU eviction for _cache_locate_site_class (fixes #1276)
The _cache_locate_site_class dict could grow without bound because the
existing _LOCATE_SITE_CLASS_CACHE_MAXSIZE constant was never enforced
with true LRU semantics on cache hits.
Changes:
- Replace plain dict with collections.OrderedDict for insertion-order
tracking plus O(1) move_to_end.
- On cache hit, call move_to_end(key) to promote the entry to
most-recently-used, ensuring frequently accessed entries survive
eviction.
- Eviction (already present as FIFO) now correctly evicts the
*least*-recently-used entry thanks to OrderedDict ordering.
- Add test_locate_site_class_cache_lru_eviction() to verify:
- Cache size never exceeds maxsize
- Recently accessed keys survive eviction (LRU promotion)
- Least-recently-used keys are evicted first
This is consistent with the lru_cache pattern used for _cached_snp_calls
and the prior fix for unbounded caching in veff.py (#1189).1 parent 3c2ee64 commit 7bf9a96
2 files changed
Lines changed: 69 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
798 | 801 | | |
799 | 802 | | |
800 | 803 | | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
801 | 807 | | |
802 | 808 | | |
803 | 809 | | |
| |||
943 | 949 | | |
944 | 950 | | |
945 | 951 | | |
946 | | - | |
947 | | - | |
948 | | - | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
949 | 956 | | |
950 | 957 | | |
951 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
976 | 1034 | | |
977 | 1035 | | |
978 | 1036 | | |
| |||
0 commit comments