Marc-Antoine Ruel | 34f5f28 | 2018-05-16 16:04:31 -0400 | [diff] [blame] | 1 | # Copyright 2018 The LUCI Authors. All rights reserved. |
| 2 | # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 | # that can be found in the LICENSE file. |
| 4 | |
| 5 | """Define local cache policies.""" |
| 6 | |
| 7 | |
| 8 | class CachePolicies(object): |
| 9 | def __init__(self, max_cache_size, min_free_space, max_items, max_age_secs): |
| 10 | """Common caching policies for the multiple caches (isolated, named, cipd). |
| 11 | |
| 12 | Arguments: |
| 13 | - max_cache_size: Trim if the cache gets larger than this value. If 0, the |
| 14 | cache is effectively a leak. |
| 15 | - min_free_space: Trim if disk free space becomes lower than this value. If |
| 16 | 0, it will unconditionally fill the disk. |
| 17 | - max_items: Maximum number of items to keep in the cache. If 0, do not |
| 18 | enforce a limit. |
| 19 | - max_age_secs: Maximum age an item is kept in the cache until it is |
| 20 | automatically evicted. Having a lot of dead luggage slows |
| 21 | everything down. |
| 22 | """ |
| 23 | self.max_cache_size = max_cache_size |
| 24 | self.min_free_space = min_free_space |
| 25 | self.max_items = max_items |
| 26 | self.max_age_secs = max_age_secs |
| 27 | |
| 28 | def __str__(self): |
| 29 | return ( |
| 30 | 'CachePolicies(max_cache_size=%s; max_items=%s; min_free_space=%s; ' |
| 31 | 'max_age_secs=%s)') % ( |
| 32 | self.max_cache_size, self.max_items, self.min_free_space, |
| 33 | self.max_age_secs) |