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

Updating Cache Handling #62

Closed
Timu57 opened this issue Nov 29, 2020 · 4 comments
Closed

Updating Cache Handling #62

Timu57 opened this issue Nov 29, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Timu57
Copy link
Member

Timu57 commented Nov 29, 2020

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()
  • disableCache()
  • useCache()
  • deleteCache()
  • deleteAllCache()

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:

  • First Part: Query
  • Second Part: File Content

MD5 and SHA hashes in raw form are binary, however their common representation is a hex-encoded string, which contains characters [a-fA-F0-9].

So if this is what you meant, then characters G-Z, g-z are "excluded".

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:

  • update()
  • delete()

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:

  • makeCache
  • deleteCache

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.

@rakibtg
Copy link
Member

rakibtg commented Nov 29, 2020

@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 auto_cache config for now.

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?

@Timu57
Copy link
Member Author

Timu57 commented Nov 29, 2020

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.
So we can delete all cache files regarding the content, no matter which query.

@Timu57
Copy link
Member Author

Timu57 commented Nov 29, 2020

As a developer I would like to have an easy configurable option to disable cache for the store, so let's keep the auto_cache config for now.

You are right. I also think we should keep the auto_cache configuration and useCache/ disableCache methods. Freedom is important 😄

@Timu57
Copy link
Member Author

Timu57 commented Dec 18, 2020

This approach for a caching system is unfortunately not possible.
A caching system with cache lifetime is implemented with #68.

@Timu57 Timu57 closed this as completed Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants