-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
39 lines (27 loc) · 976 Bytes
/
cache.py
File metadata and controls
39 lines (27 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Dict
class CachedPage:
def __init__(self, data: bytes):
self.data = bytearray(data)
self.dirty = False
class PageCache:
def __init__(self):
self._cache: Dict[int, CachedPage] = {}
def get(self, block_addr) -> CachedPage:
return self._cache[block_addr]
def put(self, block_addr, data: bytes):
self._cache[block_addr] = CachedPage(data)
def is_cached(self, block_addr) -> bool:
return block_addr in self._cache
def get_dirty_pages(self):
return [(block_addr, page) for block_addr, page in self._cache.items() if page.dirty]
class DentryCache:
def __init__(self):
self._cache = {}
def get(self, path: str):
return self._cache.get(path)
def put(self, path: str, ino: int):
self._cache[path] = ino
def remove(self, path: str):
if self.get(path) is None:
return
del self._cache[path]