powersync-js icon indicating copy to clipboard operation
powersync-js copied to clipboard

@powersync/attachments deletes synced items from storage when greater than cacheLimit

Open riisi opened this issue 7 months ago • 2 comments

My expectation of the way cache should work (it's a little unclear from the docs) is that the cache is a local cache, and @powersync/attachments should manage the size. The full set of current (not-orphaned/archived) data should remain on remote.

In testing, I found that if cacheLimit is set to a low value, e.g., 2, then only 2 items are preserved in (remote) storage. So the cacheLimit effectively applies to both local and remote files.

Inspecting the source seems to confirm this -

The delete method deletes from both local and remote: https://github.com/powersync-ja/powersync-js/blob/ba72a58ea2d6bbb9cf2fbd2c16d0045b6b758f91/packages/attachments/src/AbstractAttachmentQueue.ts#L224-L250

delete() is called from expire() to delete the oldest synced or archived attachment: https://github.com/powersync-ja/powersync-js/blob/ba72a58ea2d6bbb9cf2fbd2c16d0045b6b758f91/packages/attachments/src/AbstractAttachmentQueue.ts#L513-L531

Am I missing something here?

riisi avatar Sep 13 '25 00:09 riisi

I think that whether or not your the data is deleted remotely depends on how you implement your storage method, since powersync leaves it up to us to implement.

I've recently been implementing this myself, and have it such that the files aren't deleted remotely.

hunterbmiller avatar Sep 13 '25 21:09 hunterbmiller

To my knowledge, the JS attachment package does not support deleting attachments on the remote service. IIRC, it only supports uploads and downloads.

From looking at the code, the expireCache deletes the records and local files for synced and archived attachments. This specifically does not delete records for pending uploads - these should continue to be uploaded. While any synced records should be resynced after the delete.

FWIW the definition of the cache is a bit odd in this version. In other versions of the attachment helpers we define the cache as mentioned in your post - only archived data is treated as being present in the cache (we don't delete synced records).

stevensJourney avatar Sep 16 '25 07:09 stevensJourney