Skip to content

enh-cache fallback implemented - #55

Open
Louser21 wants to merge 1 commit into
shaaravraghu:mainfrom
Louser21:enh/cache-fallback
Open

enh-cache fallback implemented#55
Louser21 wants to merge 1 commit into
shaaravraghu:mainfrom
Louser21:enh/cache-fallback

Conversation

@Louser21

Copy link
Copy Markdown

This PR resolves the issue where a cache miss in the primary RAM cache caused the application to fail after attempting only a single fallback method.

We have introduced a structured, extensible layered cache strategy (FallbackChain) that ensures retrieval attempts cascade sequentially through all available storage tiers in order of speed before ultimately failing.

Changes Made
Unified Fallback Chain: Created src/storage/fallback.rs introducing a generic CacheLayer trait and a sequential FallbackChain.
Storage Layers: Implemented RamLayer (Fastest), DiskLayer (Medium), and VaultLayer (Slowest/Encrypted).
Disk ID Retrieval: Added retrieve_by_id in disk.rs to allow targeted disk lookups without having to reload the entire cache state.
Engine Integration: Refactored src/engine.rs (specifically decrypt_slot) to utilize FallbackChain::retrieve() instead of hardcoding a direct call to the Vault.
Automatic Promotion: When an entry is found in a slower layer (like Disk or Vault), it is now automatically promoted back into the active RAM cache to optimize subsequent retrievals.
Resilience: If one layer fails (e.g., file lock on disk), the chain safely catches the error and continues to the next available layer instead of crashing the retrieval pipeline.
Testing: Added unit tests verifying the fallback chain order.

@Louser21

Copy link
Copy Markdown
Author

hi @shaaravraghu
the changes can be cleanly merged after the rebase i did
you can proceed with this PR

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is so many changes needed to deal with fallback? The entire codebase is getting changed here. I need you to re-verify your commit.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire cache fallback feature legitimately requires only 5 files:

src/storage/fallback.rs — new file (the chain itself)
src/storage/disk.rs — add retrieve_by_id
src/storage/mod.rs — export the new module
src/engine.rs — swap the load_from_vault call
src/storage/ram.rs — removing capacity is debatable but related

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo.toml
Moves core-graphics, core-foundation, and objc into a [target.'cfg(target_os = "macos")'.dependencies] block. This is Linux-porting infrastructure, not cache fallback work.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/clipboard/mod.rs
Removes pub use types::{ClipData, ClipEntry, EntryId} from the public re-exports. This is a breaking API change with no justification in the context of this issue.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/clipboard/pasteboard.rs
Wraps the entire NSPasteboard implementation in #[cfg(target_os = "macos")] and adds Linux stubs. This is a full Linux port of the clipboard layer — completely unrelated to caching.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/config.rs
Removes the ring_capacity field from Config and the .clamp(10, 500) guard entirely. This deletes a documented user-configurable feature and is a regression unrelated to this issue.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/daemon/plist.rs
Wraps launchd logic in #[cfg(target_os = "macos")] and adds a Linux stub module. Daemon porting work, not cache fallback.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/daemon/status.rs
Wraps the launchd status check in a #[cfg(target_os = "macos")] block with a Linux fallback. Daemon work, not cache fallback.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/hotkey/chord.rs
Adds is_cmd_key() / is_cmd_held() with platform cfg variants so Ctrl is used as the modifier on Linux. Cross-platform hotkey porting — not related to the issue.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/hotkey/grabber.rs
Wraps the entire CGEventTap implementation in #[cfg(target_os = "macos")] and adds a brand-new Linux rdev::listen implementation. This is the largest single chunk of unrelated code in this PR.

@shaaravraghu shaaravraghu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/hotkey/injector.rs
Replaces hardcoded Key::MetaLeft with a MOD_KEY constant (ControlLeft on Linux). Cross-platform injector porting, unrelated.
src/hotkey/mod.rs
Removes simulate_paste from the public re-exports. This is a breaking change — any caller outside the module will fail to compile. No justification given and no relation to this issue.
src/main.rs
Removes the --ring-capacity CLI flag from the Run subcommand and strips the ring_capacity_override logic from run_service(). This removes a documented, user-facing CLI option and is a regression unrelated to the cache fallback feature.
src/notify.rs
Splits notify() into notify_macos() and notify_linux() with #[cfg] guards. Linux-porting refactor, not related to the issue.
target/release/clipwallet (binary)
Compiled binaries must never be committed to source control. Please ensure target/ is in .gitignore and remove this from the PR. This inflates the repository and is a potential security risk.
target/release/clipwallet.d (build artifact)
This build metadata file leaks your local filesystem path (/home/vyrion/Documents/Contri/ClipWallet/...) and overwrites the project maintainer's path that was previously tracked. Both files under target/ must be removed.

@Louser21

Copy link
Copy Markdown
Author

Some of the changes were done to make the project work in Linux requiring to change cargo.toml apart from that I'll fix things right away

And also suggest methods to run these in my system

@xthxr xthxr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the plan related to the issue. If any additional files/ resources are added for checking functionality/ testing; please remove them. Please provide a clean commit. @Louser21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Optimise cache fallback with a layered retrieval strategy

3 participants