MCPcopy Create free account
hub / github.com/TheSecuredAnalyst/security-suite / get

Method get

core/cache.py:88–138  ·  view source on GitHub ↗

Retrieve cached scan result if available and not expired. Args: target: Target string modules: Modules that were run options: Module options used Returns: Cached ScanResult if available and valid, None otherwise

(
        self,
        target: str,
        modules: list[str],
        options: dict[str, Any] = None,
    )

Source from the content-addressed store, hash-verified

86 return self.cache_dir / f"{checksum}.json"
87
88 def get(
89 self,
90 target: str,
91 modules: list[str],
92 options: dict[str, Any] = None,
93 ) -> ScanResult | None:
94 """Retrieve cached scan result if available and not expired.
95
96 Args:
97 target: Target string
98 modules: Modules that were run
99 options: Module options used
100
101 Returns:
102 Cached ScanResult if available and valid, None otherwise
103 """
104 checksum = self._compute_checksum(target, modules, options)
105
106 # Check memory cache first
107 if checksum in self._memory_cache:
108 entry = self._memory_cache[checksum]
109 if not entry.is_expired():
110 logger.debug(f"Cache HIT (memory) for {target}")
111 return ScanResult(**entry.result_data)
112 else:
113 # Remove expired entry
114 del self._memory_cache[checksum]
115 logger.debug(f"Cache entry expired for {target}")
116
117 # Check disk cache
118 cache_path = self._get_cache_path(checksum)
119 if cache_path.exists():
120 try:
121 with open(cache_path) as f:
122 data = json.load(f)
123 entry = CacheEntry(**data)
124
125 if not entry.is_expired():
126 logger.debug(f"Cache HIT (disk) for {target}")
127 # Restore to memory cache
128 self._memory_cache[checksum] = entry
129 return ScanResult(**entry.result_data)
130 else:
131 # Remove expired file
132 cache_path.unlink()
133 logger.debug(f"Deleted expired cache file for {target}")
134 except Exception as e:
135 logger.warning(f"Error reading cache file {cache_path}: {e}")
136
137 logger.debug(f"Cache MISS for {target}")
138 return None
139
140 def set(
141 self,

Callers 15

test_cache_expirationMethod · 0.95
db.pyFile · 0.45
upsert_runFunction · 0.45
upsert_findingFunction · 0.45
insert_remediationFunction · 0.45
exportMethod · 0.45
clearMethod · 0.45
display_resultFunction · 0.45
exploit_searchFunction · 0.45
ai_correlateFunction · 0.45
ai_remediateFunction · 0.45
runFunction · 0.45

Calls 5

_compute_checksumMethod · 0.95
is_expiredMethod · 0.95
_get_cache_pathMethod · 0.95
ScanResultClass · 0.90
CacheEntryClass · 0.85

Tested by 4

test_cache_expirationMethod · 0.76
test_cache_missMethod · 0.36