Skip to content

first and exists methods does not use cache #82

Closed

Description

@Timu57

We should consider making first and exists methods use caching.

Activity

  1. added
    enhancement
    on Jan 13, 2021
  2. added this to the Version 2.1 milestone on Jan 13, 2021
  3. rakibtg commented on Jan 13, 2021

    @rakibtg
    Member

    Is they are not already?

  4. Timu57 commented on Jan 13, 2021

    @Timu57
    MemberAuthor

    Yes, it does not use caching at the moment because the following situation is a little bit tricky if caching is enabled, at least the way it works at the moment:

    $qb = $store->createQueryBuilder();
    $qb->where('name', "=", "abc")->getQuery()->first() // returns one document and caches it
    
    $qb = $store->createQueryBuilder();
    $qb->where('name', "=", "abc")->getQuery()->fetch() // returns one document, because of the cache

    The token is set in the Cache object once on creation.

    I thought about multiple ways to solve this issue and I think the best solution could be to either:

    1. Create two new methods called setTokenAddition and removeTokenAddition
    2. Add a new optional parameter called $cacheTokenAddition to most methods of the Cache class

    PS: The solutions are meant for internal use but of course they also can be used outside.

    1. Solution

    function setTokenAddition(array $tokenAddition): Cache
    function removeTokenAddition(): Cache
    Pro Con
    Easy to use Cache Class is stateful
    Easy to implement If not removed it can have not wanted side effects
    More versatile
    Other methods have nothing to do with the cache addition

    Example with one addition:

    $cache = $query->getCache();
    
    $cache->setTokenAddition(["oneDocument"]);
    $cache->set($content); 
    $cache->removeTokenAddition();

    Example with two additions:

    $cache = $query->getCache();
    
    $cache->setTokenAddition(["oneDocument", "abc"]);
    $cache->set($content); 
    $cache->removeTokenAddition();

    2. Solution

    Example implementation with get:

    function get(array $cacheTokenAddition = []): array|null

    Example implementation with set:

    function set(array $content, array $cacheTokenAddition = [])
    Pro Con
    Cache Class is stateless regarding the token addition The token addition has to be given to most methods
    Removal can not be forgotten A little bit harder to implement
    Easy to use Every method will have to handle the token addition
    Also versatile

    New Cache File Naming

    Info Ubuntu Filesystem
    Max word length 255
    Max path length 4096
    <CacheToken>.<CacheTokenAddition>.<Lifetime>.<FileExtension>
    
    7b6ed11036bb6302cf3fdf5d120e3bfc.f25f99e4e4b133bcef5c43e8c961f779.no_lifetime.json
    

    Current max file name length is 82:

    • CacheToken: 32
    • CacheTokenAddition 32
    • LifeTime: 11
    • FileExtension: 4
    • Dots: 3

    What I would prefer

    I think both solutions are good in their own way but I tend towards the first solution.

  5. rakibtg commented on Jan 14, 2021

    @rakibtg
    Member

    @Timu57 The idea behind the first solution is to be able to add a custom value to the token? I think in previous implementation we used to use the flag for each method, in this case it was probably returnFirst something like that. So, now instead we will introduce a new method that we can manually add a value to the token?

  6. Timu57 commented on Jan 14, 2021

    @Timu57
    MemberAuthor

    @Timu57 The idea behind the first solution is to be able to add a custom value to the token? I think in previous implementation we used to use the flag for each method, in this case it was probably returnFirst something like that. So, now instead we will introduce a new method that we can manually add a value to the token?

    The method will be added to the Cache class, means the user normally never comes in contact with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementrelease candidate

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions