grantjenks / python-diskcache

Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.
http://www.grantjenks.com/docs/diskcache/
Other
2.25k stars 122 forks source link

Can this awasome add the range selection Feature? #301

Open liuzhijun opened 6 months ago

liuzhijun commented 6 months ago

can take a reference here: https://plyvel.readthedocs.io/en/latest/user.html#iterators

samples like:

for key, value in db.iterator(start=b'key-2', stop=b'key-4'):

for key, value in db.iterator(start=b'key-3'):

for key, value in db.iterator(start=b'key-2', include_start=False, stop=b'key-5', include_stop=True):

for key, value in db.iterator(prefix=b'ke'):

...etc

I can also submit a PR if ok.

Thank you !!

grantjenks commented 6 months ago

It sort of already exists with the iterkeys method.

I think I would also rather base the API on https://grantjenks.com/docs/sortedcontainers/sortedlist.html#sortedcontainers.SortedList.irange

Please describe your use case further.

liuzhijun commented 6 months ago

Yes, I think it's OK. Sorted Containers's irange api also works!

The idea that the requirements for range selection was come from the foundationdb's api. From here: https://apple.github.io/foundationdb/data-modeling.html#the-core-data-model

What's more amazing is the tuple based key operation(pack and uppack) in foundation db's Python API that can apply to any sorted persistent storage that lead to a amazing OLTP persitent layer. take a api usage here: https://apple.github.io/foundationdb/class-scheduling.html the tuple based api here: https://apple.github.io/foundationdb/api-python.html#api-python-tuple-layer

That's all why I think the persistent container should support range selection based on the start and end key.

Thank you again for your kindly comment and such a amazoning library !!