Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Cache misses on non-trivial URL structures #476

@4storia

Description

@4storia

https://github.com/stormpath/stormpath-sdk-node/blob/master/lib/cache/CacheHandler.js#L79

^ Cache entry lookup does a split on the resource href to determine which cache region to perform get/put against. Unfortunately, if I make a request for something more complicated than a region, such as an account's associated groups, this splits against https://api.stormpath.com/v1/accounts/<accId>/groups, which results in the cache region being <accId>, rather than accounts. In essence, because this is not a valid cache region, no cache entry is ever created for this request, meaning every request for an account's groups results in an API call.

As a rudimentary tweak, I would change this logic to from href.split('/').slice(-2)[0] to href.split('/').slice(4)[0], but I'm obviously not intimately familiar with this code, so there may be a reason the code wasn't written that way.

In any event, what I'm really after is a way to cache a user account AND that user's corresponding groups. Because requesting accounts via client.getAccount(href, { expand: 'groups' }) results in the cache being skipped entirely, I figured I would just make two separate API calls and then combine the results. Group memberships change very infrequently in my application, so it makes a lot more sense to cache these values than to request them fresh every time I need them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions