Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:47:49+00:00 2026-05-22T21:47:49+00:00

I have data in a DB that have hierarchical relationship (could be represented as

  • 0

I have data in a DB that have hierarchical relationship (could be represented as a tree).
Right now, whenever a request comes in the server, a recursive query is done in the DB to create an in-memory list (which is a branch of the tree, from leaf to root that actually exists) and
do processing using that list.
This is not very efficient, but at least it works for now, and has the advantage that if the DB is changed, the changes gets immediately noticed.
Anyway, I want to improve it and looking for a pattern to:
1)Not to have to access the DB all the time
2)If a change is done in the DB, it gets immediatelly reflected
3)It can be used in all places of the server.
Is there a standard design pattern commonly used for cases like this? Or just have a data structure maintained by a backend thread and on any update in the DB, reload everything in the data structure?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:47:50+00:00Added an answer on May 22, 2026 at 9:47 pm

    Instead of a thread you could use a caching solution. The result of the query would be cached and returned on every request, if any of the tables in the query are modified you invalidate the cache, wait until the next request to retrieve the new values and load them on the cache. This solution meets requisites 1 and 2. What do you mean by “It can be used in all places of the server”?

    If you are using Hibernate, this can be easily done with the second level cache, the caveat is that you must guarantee that only your application changes the database (no external processes).

    If you are not using Hibernate, you can roll your own solution with Ehcache. You would need to change the method that returns the structure to check the cache before querying the DB. Methods that make changes to the tables involved, would have to modified to invalidate the cache.

    Ehcache also has integration with Spring, but I’ve never tried it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains hierarchical data. I want to present this data
I have a php script that takes hierarchical data from a mysql procedure and
I have an asp.net backend that creates Hierarchical Data based on IHierarchicalEnumerable. This was
I have a table with well over 5 millions rows, that contains hierarchical data
I have data structured in a hierarchical manner, that when being rendered with the
I have a TreeView that allows users to select certain elements of hierarchical data
Say that have the following CTE that returns the level of some tree data
I have this project that displays hierarchical data with huge amounts of text, and
I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC
I have data that needs to be executed on a certain background thread. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.