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

  • Home
  • SEARCH
  • 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 4607562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:43:14+00:00 2026-05-22T00:43:14+00:00

Edit: For simplicity, and in order to try and make this question and the

  • 0

Edit: For simplicity, and in order to try and make this question and the sample code more generic, I left out a detail. A detail which, in light of one of the responses (which was great), turns out to be important. This system will be used primarily to show things within a date range. The low/high numbers in the code will often represent Unix timestamps the range of which could span weeks or months. End Edit

I have a page where I provide a view of data objects which have properties that fall within a certain range. As the user interacts with the view to change it, it generally is a sequential change to the range (0-9, 10-19…). I am retrieving this data from the server, and as it comes in I cache it such that a subsequent request for data in that range is already available. On each read of the data, I first check to see if I have the cache data, and if not I read it from the server and adjust the cache.

A crude, overly simplified example is here:

var cache, haveCache, read;

cache = {
    rangeLow: 0,
    rangeHigh: 10,
    data: [
        //whatever has been read so far between current low and high
        {
            low: 1,
            high: 3,
            // ...other props
        },
        {
            low: 5,
            high: 6,
            // ...other props
        },
        //...
    ]
};

haveCache = function( low, high )
{
    return ! ( low < cache.rangeLow || high > cache.rangeHigh );
};

read = function( low, high )
{
    var data;

    if( ! haveCache( low, high ) )
    {
        //go to outside source and read in info , then merge to cache
        //
        // when merging to cache:
        //    if `low` param is lower than `cache.rangeLow`, overwrite cache.rangeLow with `low`
        //    if `high` param is higher than `cache.rangeHigh`, overwrite `cache.rangeHigh` with `high`
    }

    //read data from cache

    return data;
};

This works great as long as the change in range really is sequential. However, I realized there is a way to change the view non-sequentially and skip a large set of values. So Let’s say I am currently showing for ranges 10-19, and I have a cache holding for ranges 0-29. Then the user asks for a view of data for range 60-69. The way it currently works, I’ll ask the server for data and get it back and present it fine. But now the cache rangeLow and rangeHigh run from 0-69 while it only actually holds data for ranges 0-29 and 60-69. Items with properties ranging 30-59 are not in the cache and will never be retrieved.

What (better, efficient) mechanism or algorithm can I use to store cached information and determine whether my current displayed range is in the cache?

Thanks very much,
Jim

  • 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-22T00:43:14+00:00Added an answer on May 22, 2026 at 12:43 am

    You seem to have “chunks” of data with a range of 10 objects each. Calculate how many of these chunks you can store in your cache, let’s call this cache_size. Now you can use a list of chunks you have in your cache, f.e. for cache_size 4:

    20-29
    0-9
    40-49
    30-39
    

    It will be a bit more complicated this way to maintain this list and to check if a certain object is in the cache, but I think it’s worth the effort.

    You might also think about keeping a time or date index with each chunk to determine when an object from it was retrieved the last time so when your cache is full and you’ll have to discard a cached chunk, you can discard the oldest.

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

Sidebar

Related Questions

EDIT : Let's try this again. This time I've used the AdventureWorks sample database
Edit For simplicity: I just want to make the most basic possible cursor that
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT : It turned out that this can only be done through an external
I have a windows form which has 1 button (for simplicity). On clicking this
I want to make my Scala code more readable, so I added custom types
Edit (updated question) I have a simple C program: // it is not important
EDIT: Simple version of the question: I want to create server variables in the
For the sake of simplicity, let's say that we have input strings with this
EDIT: For the sake of simplicity: I've got a simple UserJS script (FF/Chrome: Greasemonkey,

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.