kordlib / cache

MIT License
18 stars 2 forks source link

cache rewrite #11

Open HopeBaron opened 1 year ago

HopeBaron commented 1 year ago

This PR is to:

lukellmann commented 1 year ago

could you provide some examples how you think this all should be used (maybe also compared to the old cache api)? that way it will be easier to review because i would know what i'm looking at and what the intention was.

HopeBaron commented 1 year ago

@Lukellmann https://gist.github.com/HopeBaron/8417dbbbfa814be381b8c8498f4ba534 Above is a full example output:

{SnowflakeSetIndex(snowflakes=[1, 123])=MemberData(guildId=1, userId=123)}
{SnowflakeSetIndex(snowflakes=[123])=UserData(userId=123)}
{}
{}
lukellmann commented 1 year ago

what i just realized is a problem with Cache.filter and Cache.firstOrNull: these will always have O(n) complexity because all objects have to be accessed to be filtered.

HopeBaron commented 1 year ago

Yeah but the implementation doesn't specify a Key no more if you are looking for something you can identify you can easily add that sort of data to your key. Create a key out of it, and get it.