Skip to content

Conversation

@awolverp
Copy link
Owner

@awolverp awolverp commented Apr 4, 2025

In this update I focused on new features and fixing some known issues:

  • Refactor the cache classes, implement the Rust classes inside the Python instead of using stub-files - this help users to use classes as subclass and customize them.
    • BaseCacheImpl
    • Cache
    • FIFOCache
    • RRCache
    • LRUCache
    • LFUCache
    • TTLCache
    • VTTLCache

Example

class CustomRRCache(cachebox.RRCache):
    def new_method(self):
        key = self.random_key()
        print("deleting", key)
        del self[key]

c = CustomRRCache(0, {1:2, 3:4})
c.new_method()
# deleting 1
  • Don't ignore errors while doing __eq__ operations - This might slow things down a bit but needs to be fixed

Example

class A:
    def __hash__(self):
        return 1

    def __eq__(self, other):
        raise NotImplementedError("not implemeneted")

cache = cachebox.FIFOCache(0, {A(): 10})

# Before update:
cache[A()] # => KeyError

# After update:
cache[A()]
# Traceback (most recent call last):
# File "script.py", line 11, in <module>
#    cache[A()]
#    ~~~~~^^^^^
#  File "script.py", line 7, in __eq__
#   raise NotImplementedError("not implemeneted")
# NotImplementedError: not implemeneted
  • Change and optimize my isize to u64 strategy in Rust - This can make things faster
  • Update dependencies
  • Update docs and changelog

awolverp added 16 commits March 31, 2025 13:52
- Optimize the `isize` to `u64` strategy
- Now we don't ignore the errors white doing equal operations
Fix some bugs
Write tests for FIFOCache and Cache
Optimize some operations
Write FIFOCache
- The `n` parameter of the `LRUCache.least_recently_used` method has been removed
- The strictness in `__eq__` methods was reduced
@awolverp
Copy link
Owner Author

According to my benchmarks, this update makes all cache classes a bit slower, but it remains the fastest caching library in Python. The added features and resolved issues justify the trade-off ...

@awolverp awolverp added Feature New feature or request Refactor labels Apr 12, 2025
* Remove subclass flag of core classes
* Set __slots__ for cache classes
* Do some runtime optimizations
* Add some new methods to VTTLCache: `expire`, `items_with_expire`, `items`
* Optimize update methods
@AlePiccin
Copy link

@awolverp Great work! I'm a big fan of the library. I use it in many personal projects and at work. Recently I had to scale up one system at work to many processes, so I had to abandon the library as it doesn't have Redis support. I imagine it isn't the scope and main focus of this library, but do you plan adding support for a Redis backend? It would be awesome! Currently there's no cache library in python with Redis support that handle both sync and async fuctions.

@awolverp
Copy link
Owner Author

@awolverp Great work! I'm a big fan of the library. I use it in many personal projects and at work. Recently I had to scale up one system at work to many processes, so I had to abandon the library as it doesn't have Redis support. I imagine it isn't the scope and main focus of this library, but do you plan adding support for a Redis backend? It would be awesome! Currently there's no cache library in python with Redis support that handle both sync and async fuctions.

Thank you very much for your support ❤️. I will add support for Redis but it will take some time, I won't be able to add it soon.

@awolverp awolverp merged commit 061b791 into main Apr 18, 2025
11 checks passed
@awolverp awolverp deleted the morefeatures branch November 1, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants