Skip to main content

CacheManager

Struct CacheManager 

Source
pub struct CacheManager { /* private fields */ }
Expand description

Manages cache directory and cache file operations

Implementations§

Source§

impl CacheManager

Source

pub fn with_dir(cache_dir: PathBuf) -> Self

Create a new CacheManager for the given app name Create a CacheManager rooted at an explicit directory (primarily for testing).

Source

pub fn new(app_name: &str) -> Result<Self>

Create a CacheManager for the given app name.

DATUI_CACHE_DIR overrides the location. The test suite sets it, because opening a dataset records it as recent — without the override a test run writes its fixtures into the developer’s own recent-files list.

Source

pub fn cache_dir(&self) -> &Path

Get the cache directory path

Source

pub fn cache_file(&self, filename: &str) -> PathBuf

Get path to a specific cache file

Source

pub fn ensure_cache_dir(&self) -> Result<()>

Ensure the cache directory exists

Source

pub fn clear_file(&self, filename: &str) -> Result<()>

Clear a specific cache file

Source

pub fn clear_all(&self) -> Result<()>

Remove every cache kind’s directory and every line-file list (recents, histories, hidden sources, remembered places).

Nothing else: lock files may be held by another instance, the log is not a cache, and Data Quality’s copies belong to the sessions holding them. Views live in the config directory.

Source

pub fn load_history_file(&self, history_id: &str) -> Result<Vec<String>>

Load history from a history file.

A file that cannot be read is an error, never an empty list: an empty list would be written back by the next push, and every entry would be gone. A line that is not UTF-8 is skipped alone, so one bad byte costs one entry.

Source

pub fn update_history_file<F>( &self, history_id: &str, update: F, ) -> Result<HistoryUpdate>
where F: FnOnce(&mut Vec<String>),

Apply update to a history file, with the whole read-modify-write held under an exclusive lock.

Writing atomically stops two instances producing a corrupt file, but not a lost one: both read [x, y], one writes [a, x, y] and the other [b, x, y], and whichever lands second wins outright. Opening two datasets at once is ordinary — a launcher, a file manager, two terminals — so the read and the write have to be one operation.

The lock is waited for, but only briefly. The critical section is reading and rewriting a fifty-line file, so even a dozen contending instances clear in a few milliseconds; a deadline well beyond that loses nothing in practice while still guaranteeing an interactive action is never held up by a peer that has wedged. Past the deadline the update is dropped — history is a convenience, and it is never worth delaying what the user actually asked for.

Giving up after a couple of quick attempts is not enough: with several opens landing together, some are then dropped, which is the very loss this exists to prevent.

Source

pub fn save_history_file( &self, history_id: &str, history: &[String], ) -> Result<()>

Save history to a history file

Source§

impl CacheManager

Source

pub fn load_recents(&self) -> Vec<PathBuf>

Recently opened dataset paths, most recent first.

This is the only thing datui remembers about your data between runs. It is a convenience, not a record: deleting it loses nothing but ordering.

Source

pub fn load_recents_with_visits( &self, ) -> (Vec<PathBuf>, HashMap<PathBuf, Visits>)

Recents, most recent first, and how often and how lately each was opened, by its path as recorded: one read of the list.

Source

pub fn load_folds(&self) -> HashMap<String, bool>

Which home-screen sections the user folded or opened, by title.

One line per section, title<TAB>1 for folded and title<TAB>0 for opened. A section not listed takes its own default.

Source

pub fn save_folds(&self, folds: &HashMap<String, bool>)

Remember the fold state. Failing to write it loses nothing but a preference.

Source

pub fn terminal_mode(&self, terminal: &str) -> Option<ThemeMode>

The mode terminal last said its background was, for the first frame of the next start under theme.mode = "auto". One line per terminal: key<TAB>dark.

Source

pub fn remember_terminal_mode(&self, terminal: &str, mode: ThemeMode)

Remember what terminal answered, when it differs from what is remembered.

Source

pub fn forget_recent(&self, path: &Path)

Forget a single recently opened path.

A recents list you cannot edit is one people stop trusting: an experiment, a file that would not open, something private — all land there, and clearing the whole cache to remove one is too blunt.

Source

pub fn forget_recents(&self, paths: &[PathBuf])

Forget several recently opened paths at once: every recent under one place.

Source

pub fn clear_recents(&self)

Forget every recently opened path, leaving other caches alone.

Source

pub fn push_recent(&self, path: &Path) -> HistoryUpdate

Record a path as most recently opened, de-duplicating and capping the list.

Failures are ignored: not being able to write a convenience list must never interfere with opening data. The return value distinguishes a write from a contended skip for callers and tests that care; the normal caller does not.

Source

pub fn load_visits(&self) -> HashMap<PathBuf, Visits>

How often and how lately each recent was opened, by its path as recorded.

Source§

impl CacheManager

Source

pub fn dataset_shapes_kept(&self) -> usize

How many dataset shapes are kept.

Source

pub fn dataset_shape( &self, path: &str, fingerprint: &str, ) -> Option<DatasetShape>

What datui remembers about one dataset, if the fingerprint still matches.

Taking the fingerprint as an argument rather than returning the entry and letting the caller check is deliberate: an entry whose fingerprint has moved on describes a dataset that no longer exists, and there is no use for it that is not a mistake. A hit counts as use, so the datasets that never change, with the most to gain, are not the first to age out.

Source

pub fn has_dataset_shape(&self, path: &str) -> bool

Whether a shape is kept for path at all, whatever it was taken against: one stat, so a caller can tell whether listing the dataset could find it.

Source

pub fn save_dataset_shape(&self, path: &str, shape: DatasetShape)

Remember one dataset’s shape, keeping the others while they fit the budget.

Source

pub fn file_footers(&self, path: &str) -> Option<FileFooters>

The footers counts of the dataset at path have read, by file.

Source

pub fn save_file_footers(&self, path: &str, footers: &FileFooters)

Remember the footers a count of the dataset at path read, by file.

Source

pub fn cloud_listing(&self, id: &str, fingerprint: &str) -> Option<CloudListing>

The last listing of cloud source id, if it was taken at fingerprint.

Source

pub fn load_cloud_listings(&self) -> HashMap<String, CloudListing>

Every source’s last listing, by source ID.

Source

pub fn save_cloud_listing(&self, id: &str, listing: CloudListing)

Record one source’s listing, keeping the others.

Source

pub fn load_hidden_cloud_sources(&self) -> Vec<String>

Source IDs hidden from the home screen with Delete.

Source

pub fn hide_cloud_source(&self, id: &str)

Hide a source from the home screen until the cache is cleared.

Source

pub fn examples_hidden(&self) -> bool

Whether Delete on its heading hid the Example datasets that come with datui. Only the bundled catalog: a user’s own examples.toml still shows.

Source

pub fn hide_examples(&self)

Hide the bundled Example datasets from the home screen until the cache is cleared.

Source

pub fn load_remembered_places(&self) -> Vec<PathBuf>

The directories Ctrl+D kept here before 0.4.0, which keeps them in catalog.toml, in the order they were added.

Source

pub fn clear_remembered_places(&self)

Drop the list Self::load_remembered_places reads, once it is moved.

Source

pub fn save_remembered_places(&self, places: &[PathBuf]) -> Result<()>

Write places where Ctrl+D kept them before 0.4.0, for the migration’s tests.

Source§

impl CacheManager

Source

pub fn load_dataset_facts(&self) -> HashMap<PathBuf, DatasetFacts>

Everything datui knows about datasets it has measured before, without counting any of it as use. Unreadable records are absent: this is a cache, and failing to read it must never be worse than not having it.

Source

pub fn dataset_facts(&self, path: &Path) -> Option<DatasetFacts>

What datui knows about one dataset, counted as use.

Source

pub fn touch_dataset_facts<'a>(&self, paths: impl IntoIterator<Item = &'a Path>)

Count these datasets’ records as used: shown on the home screen, say. The least recently used go first once the records pass their budget.

Source

pub fn record_dataset_facts(&self, facts: &[(PathBuf, DatasetFacts)])

Record newly measured datasets, one file each. A path that is not UTF-8 is not recorded.

Trait Implementations§

Source§

impl Clone for CacheManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CacheManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more