-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add interface for cache? #10
Comments
That's a cool idea, but sounds tricky; the cache has to meet certain criteria to be useful (and I'm not sure even olrich supports all of the features/functionality we want/require yet). What interface do you propose? |
Might be really hard to abstract out the relevant interfaces... probably better to just have a separate plugin that is a redis version. |
Or not :) We don't know how hard it is until we try. What are the required functions of a cache module? |
I think the interface would match up to something along the lines of the following: type Cacher interface {
// Put will create a new cache item if it exists or not.
Put(key string, content []byte, duration time.Duration) error
// Add will add a cache item to the cache if the key does not
// exist.
Add(key string, content []byte, duration time.Duration) error
// Get returns a item from the cache or an error if the item
// does not exist
Get(key string) ([]byte, error)
// Forget removes an item from the cache, if the item cannot be
// removed it will return an error.
Forget(key string) error
} This is heavily inspired by the Laravel Cache interface, which is amazing, minus a few methods we might not want/need. |
We also need to be able to retrieve the TTL of an entry (for the |
Already available in Souin https://github.com/Darkweak/Souin btw |
If I may, I think that https://www.php-fig.org/psr/psr-6/ fits the model in many ways:
We may also want an Adapter interface implements the caching mechanism to store the information using a transport (fs, database, redis, olric etc.) which would give access to the Pool. In conjunction with a few reads, we can improve the above model to:
PSR-6 implements GetItems or SaveDefered but I don't think that we need these mechanism right away and would add them later on if needed. Thoughts? Also must read on cache abstractions: |
It's a good start! We also need to take into account the It's maybe doable with this interface, but maybe could we also do something taking this specific use case into account. AFIU Souin doesn't support |
Can't
|
No. Vary is typically a response header, not a request one. |
I did something to achieve this behaviour here https://github.com/Darkweak/Souin/pull/54/files#diff-3e6ce3aa20a99fc94989cf961ba2647ba8e2ff8cb4a092be15befe3efb583303 |
Can we close that as we have the dynamic loading (thanks to the external storages) and each storages that implement the interface can be used as a cache-handler storage? |
When I was looking to start working on a similar module, I stumbled across this one and I love the work that is being done on this module, this is going to be a great addition to the Caddy modules list!
The only thing I was wondering is if there could be an interface for the caching backend, similar to the certmagic storage interface so the default storage, olric, could be swapped out with something like redis?
The text was updated successfully, but these errors were encountered: