cabouman / svmbir

Fast code for parallel or fan beam tomographic reconstruction
BSD 3-Clause "New" or "Revised" License
19 stars 8 forks source link

Cache management #40

Open sjkisner opened 3 years ago

sjkisner commented 3 years ago

Add functions to "list" and "clear" sysmatrix files from cache directory.

We should use "touch" or something equivalent to update the time stamp of the sysmatrix file each time it's accessed in order to assigning priority.

smajee commented 3 years ago

So, every-time we run recon or project, we should 'touch' the sysmatrix file?

cabouman commented 3 years ago

Yes, that way its time stamp will update.

sjkisner commented 3 years ago

We can just do it in one place, under the line that prints "Found system matrix".

Not sure "touch" will work in Windows though unless it's run in a bash emulator.

bwohlberg commented 3 years ago

There's a useful discussion here on how to implement touch in an OS-independent fashion.

sjkisner commented 3 years ago

Yes! This works for me on Linux,Mac,Windows: import os os.utime(sysmatrix_name+'.2Dsvmatrix')

The above is all we need here because we just need to update the modified time for a file that exists.

cabouman commented 3 years ago

OK, we have added a touch command that updates the last modification time for the library files.

After some thought, maybe it would be best to create a separate utility svmbir.clean_lib(N) that would clean out the library and only retain the N most recent files.

Do people like this idea?

sjkisner commented 3 years ago

Sounds good. There's already a function _clear_cache() that could be modified.

I'd suggest having it default to cleaning the cache folder entirely. Like clear_cache(svmbir_lib_path=None, num_sysmatrix=0) where num_sysmatrix is number of most recent matrix files.

We should take care to identify the specified path as a valid cache folder so it can't be used to obliterate an arbitrary folder.

cabouman commented 3 years ago

We should implement a function clear_cache() that first prompts the user with something like:

Would you like to delete your cache directory? [y/n]

Then if the user responds with a y, it calls _clear_cache().

cabouman commented 2 years ago

Brendts suggestion: Perhaps allow the user to specify a maximum cache size? If writing a new file exceeds it, automatically delete the oldest files until it's under the threshold?