Skip to content

feat: Clean cache command#1394

Open
d3xter666 wants to merge 13 commits into
mainfrom
feat-clean-cache
Open

feat: Clean cache command#1394
d3xter666 wants to merge 13 commits into
mainfrom
feat-clean-cache

Conversation

@d3xter666
Copy link
Copy Markdown
Member

The command completely cleans the cache by removing the cache files as well as cleaning up the SQLite records.
It does not wipe out the SQLite DB file(s)

JIRA: CPOUI5FOUNDATION-891

@d3xter666 d3xter666 requested a review from a team May 22, 2026 12:22
@d3xter666 d3xter666 force-pushed the feat-clean-cache branch 2 times, most recently from 83f2262 to d52c4ad Compare May 26, 2026 06:29
@RandomByte RandomByte force-pushed the feat/incremental-build-4 branch from 7c59782 to 444977d Compare May 27, 2026 15:40
Comment thread packages/project/lib/cache/CacheCleanup.js Outdated
Comment thread packages/project/lib/cache/CacheCleanup.js Outdated
Comment thread packages/project/lib/cache/CacheCleanup.js Outdated
Comment thread packages/cli/lib/cli/commands/cache.js
@RandomByte RandomByte force-pushed the feat/incremental-build-4 branch from c2dc7b8 to 1041695 Compare May 29, 2026 08:11
@d3xter666 d3xter666 force-pushed the feat-clean-cache branch 2 times, most recently from dc31834 to f5def12 Compare May 29, 2026 08:29
@RandomByte RandomByte force-pushed the feat/incremental-build-4 branch from 1041695 to 66296d5 Compare May 29, 2026 08:49
@d3xter666 d3xter666 force-pushed the feat-clean-cache branch 2 times, most recently from 77f7320 to aa280da Compare May 29, 2026 10:27
Comment thread packages/project/lib/build/cache/CacheCleanup.js Outdated
@d3xter666 d3xter666 requested a review from matz3 May 29, 2026 13:21
@d3xter666 d3xter666 force-pushed the feat-clean-cache branch 2 times, most recently from 7b17cc0 to 569ff71 Compare May 29, 2026 15:44
@d3xter666 d3xter666 requested a review from a team June 1, 2026 07:46
@d3xter666 d3xter666 changed the base branch from feat/incremental-build-4 to main June 1, 2026 10:10
* @returns {Promise<boolean>} True if user confirmed
*/
async function confirm(question) {
const rl = readline.createInterface({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the server we use a library for such questions:

const ok = await yesno({

Not sure which way is better, but ideally we use the same approach in both places

.command("clean", "Remove all cached UI5 data", {
handler: handleCache,
builder: function(yargs) {
return yargs.option("interactive", {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From my experience, --yes or --force is more commonly used for this kind of option. E.g. apt get upgrade --yes or docker system prune -f

return {
path: `buildCache/${CACHE_VERSION}`,
size,
type: "database"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like the type attribute is never used (besides in tests). Do we need it?

@@ -0,0 +1,80 @@
import path from "node:path";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems odd that this file is placed next to the other files responsible for managing the framework packages but doesn't use any of them. I would expect better integration here, e.g. no hardcoded assumptions like the framework/ directory name as well as checks for existing lockfiles to prevent deleting files while a download is running

try {
const size = await getDirectorySize(frameworkDir);
if (size > 0) {
await fs.rm(frameworkDir, {recursive: true, force: true});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we actually need to specify force?

Comment on lines +71 to +72
path: "framework",
type: "framework",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is both path and type different here from getCacheInfo? (as als mentioned in CacheManager: do we actually need type?)

* @param {string} dirPath Absolute path to directory
* @returns {Promise<number>} Total size in bytes
*/
async function getDirectorySize(dirPath) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On my system this results in a different number than du:

~/.ui5
❯ du -sh framework 
 37G	framework
❯ ui5 cache clean

The following items from cache will be removed:
  • framework/ (31.9 GB)
  • buildCache/v0_7 (70.7 MB)

Total: 32.0 GB

In my case, it also takes over a minute to calculate the size, which makes me wonder whether we should really do that or rather list the number of artifacts. Something like "this will delete 500 packages across 40 versions of UI5" would be much faster to calculate - not sure yet.

export async function cleanCache(ui5DataDir) {
const frameworkDir = path.join(ui5DataDir, "framework");
try {
const size = await getDirectorySize(frameworkDir);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since it takes a long time to calculate the size of a large cache, could we skip calculating it again during the cleaning?

const dbDir = path.join(buildCacheDir, CACHE_VERSION);

try {
const storage = new BuildCacheStorage(dbDir);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we skip this if no database exists yet? Otherwise this would end up creating a new db file

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.

3 participants