Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fully support LRU caching for EntityGroups and EntityRelations. #122

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

k-r-g
Copy link
Contributor

@k-r-g k-r-g commented Mar 9, 2023

This provides a middle ground for applications with large relations and entity groups so they don't need to be fully cached (using all that heap space) but can still benefit from LRU caching and otherwise be used similar to when cached and get CacheMessageManager updates appropriately.

Note that for both LruCacheGroup and LruSqlEntityRelation, client code will want to continue to avoid operations that result in reading the full table into memory. These changes enable an application to treat these closer to their fully-cached counterparts, but client code must still beware of the performance consequences of an LruCacheGroup.list() or LruSqlEntityRelation.replaceAll() or removeAll().

  • SqlEntityRelation
    • Builder needed its members to be protected so they could be used by the new subclass in LruSqlEntityRelation.
    • leftValueList() and leftValueSet() had the same guts as leftIDs(), so change to simply use leftIDs() instead. Same for rightValueList() and rightValueSet() using rightIDs().
    • Add toString so registered relations are cleanly listed during startup.
  • CachingEntityRelation
    • Create new interface to represent functionality shared between CachedRelation and the new LruSqlEntityRelation.
  • CachedRelation
    • Implement CachingEntityRelation by changing some existing methods to @OverRide and moving their comments to the new interface.
    • Fix two bugs in CachedRelation where the wrong listener method was called in removeAll() and replaceAll().
  • LruSqlEntityRelation
    • Create new class to provide an LRU cache of relations, similar to what LruCacheGroup does for entities.
  • EntityStore
    • Change references of CachedRelation to CachingEntityRelation so LruSqlEntityRelation can be treated the same as CachedRelation.
  • LruCacheGroup
    • Add map() for querying by a set of IDs instead of relying on a separate query per desired object.
    • Add querySingle() for querying by arbitrary criteria. Useful for login when User is an LruCacheGroup.
    • Default to distribute=true so LruCacheGroups send/receive cache messages.
  • CacheMessageManager
    • Appropriately handle messages for an LruCacheGroup to keep them updated just like a CacheGroup is. This enables easier transitions from CacheGroup to LruCacheGroup.
    • Change references of CachedRelation to CachingEntityRelation so LruSqlEntityRelation can be kept updated just the same as CachedRelation.

This provides a middle ground for applications with large relations and
entity groups so they don't need to be fully cached (using all that
heap space) but can still benefit from LRU caching and otherwise be used
similar to when cached and get CacheMessageManager updates appropriately.

Note that for both LruCacheGroup and LruSqlEntityRelation, client code will
want to continue to avoid operations that result in reading the full table
into memory. These changes enable an application to treat these closer to
their fully-cached counterparts, but client code must still beware of the
performance consequences of an LruCacheGroup.list() or
LruSqlEntityRelation.replaceAll() or removeAll().

- SqlEntityRelation
  - Builder needed its members to be protected so they could be used by the
    new subclass in LruSqlEntityRelation.
  - leftValueList() and leftValueSet() had the same guts as leftIDs(), so
    change to simply use leftIDs() instead. Same for rightValueList() and
    rightValueSet() using rightIDs().
  - Add toString so registered relations are cleanly listed during startup.
- CachingEntityRelation
  - Create new interface to represent functionality shared between
    CachedRelation and the new LruSqlEntityRelation.
- CachedRelation
  - Implement CachingEntityRelation by changing some existing methods to
    @OverRide and moving their comments to the new interface.
  - Fix two bugs in CachedRelation where the wrong listener method was
    called in removeAll() and replaceAll().
- LruSqlEntityRelation
  - Create new class to provide an LRU cache of relations, similar to what
    LruCacheGroup does for entities.
- EntityStore
  - Change references of CachedRelation to CachingEntityRelation so
    LruSqlEntityRelation can be treated the same as CachedRelation.
- LruCacheGroup
  - Add map() for querying by a set of IDs instead of relying on a separate
    query per desired object.
  - Add querySingle() for querying by arbitrary criteria. Useful for login
    when User is an LruCacheGroup.
  - Default to distribute=true so LruCacheGroups send/receive cache
    messages.
- CacheMessageManager
  - Appropriately handle messages for an LruCacheGroup to keep them
    updated just like a CacheGroup is. This enables easier transitions from
    CacheGroup to LruCacheGroup.
  - Change references of CachedRelation to CachingEntityRelation so
    LruSqlEntityRelation can be kept updated just the same as
    CachedRelation.
@k-r-g k-r-g marked this pull request as ready for review March 14, 2023 23:23
@msmith-techempower msmith-techempower merged commit 5c593f9 into TechEmpower:master Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants