GithubHelp home page GithubHelp logo

yiling-j / cacheme Goto Github PK

View Code? Open in Web Editor NEW
40.0 3.0 0.0 474 KB

Asyncio cache framework for Python

License: BSD 3-Clause "New" or "Revised" License

Python 99.45% JavaScript 0.17% Makefile 0.38%
python cache asyncio framework memory redis

cacheme's Issues

type safe and elegent decorator

With the help of type hints it's possible to limit key function's signature, just the same way as Cacheme. Using a separate function avoids the weird lamda or f-string in original decorator

@Cache("tlfu", 10000)
async def get_user_info(user_id: int) -> Dict:
    return {}

# or use existing cache
cache = Cache("tlfu", 10000)
@cache
async def get_user_info(user_id: int) -> Dict:
    return {}

# register key function: function name is not important, so just use _ here
@get_user_info.key
def _(user_id: int) -> str:
    return f"user:{user_id}"

Support compress option

Add option in settings to enable compress for value byte size larger than given threshold

V2

Based on the experience of cacheme-go, proposal following improvements:

  • enforce schema/node
  • typing/asyncio support
  • multiple storages(redis/sql databases)
  • multiple serializers(pickle/json/msgpack)
  • local cache support
  • prometheus integration
  • API and admin page

Better way to set key

Now I use string to set key in decorator, this is not easy for management, also user may have typos. So separate keys into a new python file, make them class, and just import in decorator maybe a better choice

reduce overhead

Currently Cacheme overhead is too high, the local storage performance is much worse than native Theine API, need to improve: 1. try replace async event with awaitable, 2. optimize get/get_many, simplify code

Upgrade to Pydantic 2 or make Pydantic support optional?

I'm working a Starlette project that uses Pydantic v2. I'd be interested in trying out cacheme, but the conflicting Pydantic version requirements make it impossible. Two obvious options present themselves:

  1. Upgrade the Pydantic support to v2 (migration guide), or
  2. Make pydantic support optional (perhaps allow customization of object_encoder/object_decoder on the Serialization classes, with the default being an identity function for accepting/returning primitive types.

Thank you for considering this.

Limit meta keys size

Meta keys just store set of key names, for example, delete meta key set stores deleted key names. Becasue key names are always short string, to make use of hash-max-ziplist-entries and save some memory, we can just bucket key name, just as instagram do Storing hundreds of millions of simple key-value pairs in Redis.

My idea is add some options to node or node fields, so we can dynamically bucket node keys. Each node will has its own meta keys namespace, and depend on node fields, we calculate the meta key info.
Or maybe hash the key and use bitmap to store those info.

Improvements

  • Support invalid single key in node
  • Add class META to node, then we can put attributes there, for example timeout
  • Add stale option to global settings, also decorator and node
  • Add capability to define functions in node(hit/skip...)
  • Refactor code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.