GithubHelp home page GithubHelp logo

Comments (5)

sohang123 avatar sohang123 commented on August 25, 2024

Here is how we set up the backends:

redis_backend = cache.setup(
redis_url,
client_name=None,
suppress=False,
client_side=False,
middlewares=(add_prefix(f"{build_stamp}:"),),
)

mem_backend = cache.setup(
"mem://?check_interval=10&size=100000", prefix="mem:", suppress=False, enable=enable_in_memory_cache
)

This is how we are using early

Repalced:

@cache(ttl="1h", key=f"mem:{key}")
@cache(ttl="1h", key=key)

With:

@cache.early(ttl="1h", early_ttl="40m", key=f"mem:{key}")
@cache.early(ttl="1h", early_ttl="40m", key=key)

from cashews.

sohang123 avatar sohang123 commented on August 25, 2024

Update: Looks like if we do
mem_backend = cache.setup(
"mem://?check_interval=10&size=100000", prefix="early:v2:mem:", suppress=False, enable=enable_in_memory_cache
)

It works. Looks like this prefix appending causes us to have to remember to add this prefix everywhere. I don't know if this is intended behavior or not.

from cashews.

sohang123 avatar sohang123 commented on August 25, 2024

Seems like we can use set methods along side early caching. Here is a test example:

`foo_key = "foo:{id}"

async def set_foo_by_id():
await cache.set_many(
{("early:v2" + foo_key.format(id=id)): str(id) for id in [1,2,3]},
expire="1h",
)

@cache.early(ttl="1h", early_ttl="40m", key=foo_key, condition=NOT_NONE)
async def get_foo_by_id(id):
return str(id)

await set_foo_by_id()
print(await get_foo_by_id(1))`

Throws error:

/Users/sohanggandhi/fh-repos/fh-mono/prompt_server/.venv/lib/python3.11/site-packages/cashews/de │ prompt-server-online | │ corators/cache/early.py:88 in _wrap │ prompt-server-online | ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ prompt-server-online | ValueError: too many values to unpack (expected 2)

from cashews.

Krukov avatar Krukov commented on August 25, 2024

Hello, thanks for reporting

Looks like this prefix appending causes us to have to remember to add this prefix everywhere. I don't know if this is intended behavior or not.

In general, this is how it was intended, but now I understand that it is not very "user friendly". So probably I will fix it somehow. I did this because values ​​in the cache for the regular cache and early stored differently, which can lead to errors

For now I can suggest to remove this prefix by passing empty string (prefix="")

@cache.early(ttl="1h", early_ttl="40m", key=f"mem:{key}", prefix="")
@cache.early(ttl="1h", early_ttl="40m", key=key, prefix="")

from cashews.

sohang123 avatar sohang123 commented on August 25, 2024

@Krukov thanks for getting back to us. We already tried as you suggest but even with prefix="", the prefix "v2:" is still added. So doesn't fix the issue.

from cashews.

Related Issues (20)

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.