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

Caches: Refactored API #1060

Merged
merged 8 commits into from
Apr 29, 2019
Merged

Conversation

fulmeek
Copy link
Contributor

@fulmeek fulmeek commented Mar 9, 2019

Addressing issue #1037, this changes the Caches interface and current implementations to make it usable for different kind of caches:

  • The methods loadData, saveData, getTime and purgeCache stay the same. You only have to ensure they consistently return null on non-existing data.
  • Removed: setPath($path) and setParameters(array $param) were designed with file based caching in mind
  • New:
    • setScope($scope): Set scope of the current cache (replaces setPath)
      If $scope is an empty string, the cache is set to a global context. No absolute path anymore.
    • setKey($key): Set key to assign the current data (replaces setParameters)
      Since $key can be anything, the cache implementation must ensure to assign the related data reliably; most commonly by serializing and hashing the key in an appropriate way.
  • Cache implementations should check all requirements on construction (extensions, configuration). See SQLiteCache as an example.

Feel free to add comments and suggestions :)

fulmeek added 5 commits March 9, 2019 08:57
For consistency, functions should always return null on non-existing data.
WordPressPluginUpdateBridge appears to have used its own cache instance in the past. Obviously not used anymore.
Since $key can be anything, the cache implementation must ensure to assign the related data reliably; most commonly by serializing and hashing the key in an appropriate way.
Even though the default path for storage is perfectly fine, some people may want to use a different location.
This is an example how a cache implementation is responsible for its requirements.
Copy link
Contributor

@logmanoriginal logmanoriginal left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

There are two things which I think should be worked on, however. One is mentioned below, the other is about protected functions. Maybe they should be made private to prevent confusion (because they are not supported by the interface and nobody should actually inherit these classes).

So, functions like getPath, getCacheFile and getCacheName in FileCache can be private and don't need to do additional parameter validation if this is already done by the calling function.

The same should be true for getCacheKey in SQLiteCache, right?

caches/FileCache.php Show resolved Hide resolved
logmanoriginal and others added 3 commits March 25, 2019 21:35
Co-Authored-By: fulmeek <36341513+fulmeek@users.noreply.github.com>
Done earlier, but forgotten to actually add these changes to the previous commits.
The previous code suggestions to set directory permissions to 644 had to reverted to 755 as the executable bit is required to change into that folder.
@fulmeek
Copy link
Contributor Author

fulmeek commented Apr 24, 2019

Since it's been a while, any news?

@logmanoriginal
Copy link
Contributor

Since it's been a while, any news?

Yes, I'm back 🤣


Seriously though, the changes look fine to me. Good job 👍
I'm gonna merge this but also need to point to #1000 because it'll break again.

@logmanoriginal logmanoriginal merged commit 21d3bf3 into RSS-Bridge:master Apr 29, 2019
@fulmeek fulmeek deleted the upstream-Caches branch June 1, 2019 15:42
infominer33 pushed a commit to web-work-tools/rss-bridge that referenced this pull request Apr 17, 2020
- For consistency, functions should always return null on non-existing data.

- WordPressPluginUpdateBridge appears to have used its own cache instance in the past. Obviously not used anymore.

- Since $key can be anything, the cache implementation must ensure to assign the related data reliably; most commonly by serializing and hashing the key in an appropriate way.

- Even though the default path for storage is perfectly fine, some people may want to use a different location. This is an example how a cache implementation is responsible for its requirements.
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.

2 participants