-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Updating Cache Handling #62
Comments
@Timu57 This is incredible! 🥳 I always envisioned something like this, I am so glad that you came up with this idea! As a developer I would like to have an easy configurable option to disable cache for the store, so let's keep the We will not force a developer to use cache, although we will enable it by default but they should be able to disable it easily. Question: When looking for a document how will you hash the content without exploring all the documents first; in order to find the correct cache file? |
Lookups will be done like now, with the hash of the query alias QueryCacheToken. Means no changes there besides of using glob to find the path to the correct cache file. The hash of the content alias ContentCacheToken is just used to find the correct cache files when deleting and updating. |
You are right. I also think we should keep the auto_cache configuration and useCache/ disableCache methods. Freedom is important 😄 |
This approach for a caching system is unfortunately not possible. |
Overview of current state
For caching the getCacheToken method is used, which generates a md5 hash out of the query parameters.
Users can interact with Caching by using the following methods:
makeCache
Re-generate the cache for the query.
disableCache
Disable cache for the query.
useCache
Re-use existing cache or generate if it doesn't exists.
deleteCache
Delete cache for the current query.
deleteAllCache
Delete all cache of current store.
New Cache Handling
We could split/ separate the cache token into two parts with for example a dot:
https://stackoverflow.com/questions/12618321/what-pool-of-characters-do-md5-and-sha-have
New private methods
getQueryCacheToken
Returns first part of cacheToken, generated with query.
getContentCacheToken
Returns second part of cacheToken, generated with content.
getCachedFiles
Returns an array with paths to cached files. Either by QueryCacheToken or ContentCacheToken.
deleteCacheBy
Receives the ContentCache or QueryCache and uses the getCachedFiles to delete all files.
Updates
We will have to update all methods mentioned above to use the QueryCacheToken.
Also we need to update the following methods:
Deeper look
getCachedFiles
We can use PHP`s glob function https://www.php.net/manual/de/function.glob.php to find the files.
useCache
We will look for cached files with the QueryCache and the getCachedFiles method. If there are non we will generate a new cache file.
update
Before updating the content we will delete all cache files considering the old content with the ContentCache of the old content and by using the deleteCacheBy method.
delete
Before deleting a file we will delete all cache files considering the old content with the ContentCache of the old content and by using the deleteCacheBy method.
Deprecation
We could mark the following methods as deprecated because they are no longer needed:
Conclusion
Now the user of SleekDB just has to use useCache or the auto_cache configuration when generating a new store to activate caching and don't has to think about cache handling.
If the content changes the cache of it will be deleted.
If a file gets deleted the cache will be deleted too.
This solution would be compatible with old code using SleekDB.
The text was updated successfully, but these errors were encountered: