Skip to content
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

feat(cache): Add force creation option for overwriting cache #98

Merged
merged 2 commits into from
Jan 26, 2025

Conversation

mitsuki31
Copy link
Owner

@mitsuki31 mitsuki31 commented Jan 26, 2025

Overview

This pull request introduces the ability to force the creation of a cache even when an entry with the same video ID already exists. This feature ensures that developers or later implementations can overwrite outdated or incorrect cache objects with new video information, keeping the cache accurate and up to date.

Changes Made

Add New Option to Force Cache Creation

  • Introduced the cacheOptions.force parameter in the VInfoCache.createCache function to enable forced creation and overwriting of an existing cache with the same video ID.
  • Ensures that overwriting updates the cache's properties, including the createdDate value.
  • Updated the API documentation to reflect the new force option.

Add Test Case for Cache Overwrite Ability

  • Added a test case to validate that the cacheOptions.force option successfully overwrites existing cache entries.
  • Ensured the test verifies that the createdDate property is updated when an overwrite occurs.

Updated Implementation

createCache

class VInfoCache {
  // ...

  static function createCache(
    vInfo: ytdl.videoInfo,
    cacheOptions?: { cacheDir?: string, force?: boolean } | string
  ): Promise<string>
}

Impact

  • Provides flexibility for developers to maintain accurate cache entries by forcing the creation of a cache.
  • Supports potential future development scenarios that require cache entries to be refreshed or corrected programmatically.
  • Prevents reliance on manual cache deletion before overwriting, streamlining workflows for developers.

Summary

This feature introduces the cacheOptions.force option to VInfoCache.createCache, allowing cache overwriting when necessary. Unit tests and API documentation updates have been included to ensure robustness and clarity.

- Added the `cacheOptions.force` option to forcily create and overwrite the similar video ID with the specified video information object, this also makes the cache properties updated (i.e., `createdDate`)
- Updated the API documentation to describe the new option `force`
@mitsuki31 mitsuki31 added this to the YTMP3-JS v2.0.0 milestone Jan 26, 2025
@mitsuki31 mitsuki31 added feature Bring new features minor Minor changes labels Jan 26, 2025
@mitsuki31 mitsuki31 self-assigned this Jan 26, 2025
Copy link

codecov bot commented Jan 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.16%. Comparing base (ff35fa1) to head (b72300e).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #98   +/-   ##
=======================================
  Coverage   83.16%   83.16%           
=======================================
  Files          12       12           
  Lines         713      713           
=======================================
  Hits          593      593           
  Misses        120      120           
Flag Coverage Δ
Ubuntu 83.16% <100.00%> (ø)
Windows 82.88% <100.00%> (ø)
all 83.16% <100.00%> (ø)
macOS 83.16% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mitsuki31 mitsuki31 merged commit ebfc7fe into master Jan 26, 2025
26 checks passed
@mitsuki31 mitsuki31 deleted the feat/add-cache-force-creation-option branch January 26, 2025 14:40
mitsuki31 added a commit that referenced this pull request Jan 26, 2025
The return logic of the `getAllCaches` function has been improved to better align with its intended behavior, offering more predictable and meaningful responses based on the `humanReadable` option. This change enhances usability and prepares the API for more diverse use cases.

- 1246a8a - test(unit): Add test case to verify the adjusted return value
- 9992268 - fix(cache): Change the return value if no caches found

Related changes: #96, #98

---

Signed-off-by: Ryuu Mitsuki <dhefam31@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Bring new features minor Minor changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant