dicomtrolley.caching¶
Storing DICOM query results locally to avoid unneeded calls to server
CachedSearcher
¶
Bases: Searcher
A cache wrapped around a Searcher instance. Serves search responses from cache first. Calls searcher if needed.
Caches two types of searcher method calls: find_studies(Query): Caches each returned DICOM object individually and then associates this with the incoming query. Only if the query matches exactly is a cached response returned. Associates DICOM tree address (study/series/instance). Not DICOM object identities. This means that an underlying DICOM object can be updated without invalidating the cache response. The cached response to a query will be returned as long as there are non-expired cached objects at each associated tree address
find_study_by_id(study_id, level): Retrieves study_id from cache and checks whether it has children up to the required level (depth).
Source code in dicomtrolley/caching.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
find_studies(query)
¶
Try to return from cache, otherwise call searcher.
Source code in dicomtrolley/caching.py
260 261 262 263 264 265 266 267 268 269 270 271 | |
find_study_by_id(study_uid, query_level=QueryLevels.STUDY)
¶
Find a single study at the given depth
Source code in dicomtrolley/caching.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
DICOMObjectCache
¶
Source code in dicomtrolley/caching.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__init__(initial_objects=None, expiry_seconds=600)
¶
A tree holding expiring DICOM objects. Objects can be retrieved by study/series/instance UID tuples:
cache = DICOMObjectCache() cache.add(a_study) # with uid 'study1' and full series and instance info cache.retrieve(reference=('study1','series'))
cache.retrieve(reference=('study1','series','instance'))
20 minutes later... study has expired¶
cache.retrieve(reference=('study1','series'))
Parameters¶
initial_objects, optional Shorthand for add() on all objects in this list. Defaults to empty
expiry_seconds, optional Expire objects after this many seconds. If set to None, will disable expiry. Defaults to 600 (10 minutes)
Notes¶
The functionality here is similar to dicomtrolley.parsing.TreeNode, but the use case is different enough to warrant a separate class I think
Source code in dicomtrolley/caching.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
add(obj, prune=True)
¶
Add this object to cache
Returns¶
The input DICOMObject. Just so you can add and return a value in a single line in calling code. Like new_dicom = cache.add(get_new_dicom())
Source code in dicomtrolley/caching.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
prune_expired()
¶
Remove all expired nodes
Source code in dicomtrolley/caching.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
retrieve(reference)
¶
Try to retrieve object from cache
Parameters¶
reference The dicom object you would like to retrieve
Raises¶
NodeNotFound If the object does not exist in cache or has expired
Returns¶
DICOMObject The cached object
Source code in dicomtrolley/caching.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
to_address(ref)
staticmethod
¶
Convert reference to address that can be used in TreeNode
Source code in dicomtrolley/caching.py
174 175 176 177 178 179 180 181 182 183 184 | |
QueryCache
¶
Caches the response to DICOM queries
Source code in dicomtrolley/caching.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
add_response(query, response)
¶
Cache response for this query
Source code in dicomtrolley/caching.py
194 195 196 197 198 | |
get_response(query)
¶
Obtain cached response for this query
Raises¶
NodeNotFound If any of the results of query are not in cache or have expired
Source code in dicomtrolley/caching.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |