-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cacheStalePeriod
causes cache to not work properly
#233
Labels
bug 🐛
Something isn't working
Comments
|
sidrao2006
added a commit
that referenced
this issue
Jun 10, 2024
Original behaviour: A default cache manager with cache key 'DynamicCachedFontsFontCacheKey' was used which stored font files in a folder with the same name. If a value for `cacheStalePeriod` or `maxCacheObjects` is provided which differs from the default value then a new instance of `CacheManager` would be created with the generated `cacheKey`. Problem: Once a garbage collecttion event is run, `_cacheManagers` is destroyed and hence the package forgets about the modified `CacheManager` and attempts to locate the file in the default cache folder (as mentioned above). Solution: There will be no default instance of `CacheManager`, instead an instance will be created using `cacheKey` after any garbage collection events (which includes app restarts). The first time a font is stored will be done using the cache config provided and for subsequent retrievals, `CacheManger` with `cacheKey` will be used and so the package will look for the font file in the right place. See #233 BREAKING CHANGES: This commit does not include any changes to the public API. However, as mentioned above, font files which have already been cached under 'DynamicCachedFontsFontCacheKey' will no longer be used. A migration tool will be provided to delete old font files.
Merged
sidrao2006
added a commit
that referenced
this issue
Jun 11, 2024
* fix(cache-manager)!: Fix configured cache manager error ## Breaking Changes and Migration Guide 1. If you have been using the package without modifying `cacheStalePeriod` or `maxCacheObjects`, no changes are required. However, any previously cached font files will be ignored and should be deleted by running the migration tool. 2. If you have modified `cacheStalePeriod` or `maxCacheObjects`, you'll have to pass the same values to any method that downloads, caches or loads fonts, otherwise the **provided configuration will be ignored.** Any previously cached font files will continue to remain in their respective cache folders and will be used by the package. Running the migration tool will have no effect on these font files. 3. A migration tool has been provided -> `DynamicCachedFonts.runMigrationTool()` --- Original behaviour: A default cache manager with cache key 'DynamicCachedFontsFontCacheKey' was used which stored font files in a folder with the same name. If a value for `cacheStalePeriod` or `maxCacheObjects` is provided which differs from the default value then a new instance of `CacheManager` would be created with the generated `cacheKey`. Problems: 1. Once a garbage collection event is run, `_cacheManagers` is destroyed and hence the package forgets about the modified `CacheManager` and attempts to locate the file in the default cache folder (as mentioned above). 5. `CacheManager` requires a singleton approach. Since each `cacheKey` requires a unique instance of `CacheManager`, calling any method provided by the package before calling `cacheFont`/`cacheFontStream` would result in `cacheStalePeriod`, `maxCacheObjects` to be ignored when downloading and adding the font to cache. Solutions: 1. There will be no default instance of `CacheManager`, instead an instance will be created using `cacheKey` after any garbage collection events (which includes app restarts). 2. Any method that downloads, caches or loads font will now accept `cacheStalePeriod`, `maxCacheObjects` . This ensures that an instance of `CacheManager` will be created only once with the provided config Changes: - Require `cacheStalePeriod`, `maxCacheObjects` to be passed to any method that calls `getCacheManager`. As a result, if the above mentioned properties are modified by the user of the package at any point, the modified values should be passed to any method provided by this package - Require `cacheStalePeriod`, `maxCacheObjects` to be passed to `getCacheManager` - Remove `handleCacheManager` See #233 * Update unit tests for internal methods
Hello, thanks for reporting this bug. I've released v2.0.0-dev.0 with a fix. Please try it out and let me know if any further changes are required. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description of the bug
if I set a custom
cacheStalePeriod
then the font file will not be downloaded inDynamicCachedFontsFontCacheKey
cache folder, instead it will be downloaded in a new folder inside app's cache folder and with a name equal to the file url;and because of that when i restart the app and then call
DynamicCachedFonts.canLoadFont(url)
it gives false despite i did download the font before;The text was updated successfully, but these errors were encountered: