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 8915849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:05:11+00:00 2026-06-15T05:05:11+00:00

I’ve got a script that 1) runs often 2) is run by lots of

  • 0

I’ve got a script that 1) runs often 2) is run by lots of different processes and 3) takes a long time.

update: The stuff that takes a long time is tests who’s results will be the same for every process. Totally redundant.

I think it’s time to do some caching, but I’m worried about the potential for races, conflicts, corruption, temporal-vortex-instability and chickens.

The complexity comes in because any of the processes could update the cache as well as read the cache, so I have to know how to handle all those combinations.

This smells to me like something that someone smarter and more educated than myself has already probably figured out.

Anyway, to make this question more concrete, here’s what I’ve thought of so far. I’m using flock in my head, not sure if that’s a good idea.

  • if the cache is fresh, read it and go away
  • if the cache is stale
    • try to get a write lock
      • if I get the lock, do the tests and update the cache
      • If I don’t get the lock, does someone else have an write or a read lock?
      • If its shared, why are they reading a stale cache? Do I ignore them, do the tests and update the cache (or maybe this causes them to read a half-written cache… er…)
      • If it’s exclusive, give them a short time to complete the tests and update the cache.

Hope that makes sense…

  • 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-06-15T05:05:13+00:00Added an answer on June 15, 2026 at 5:05 am

    Here is a scheme which uses flock(2) for file locking in concurrent environments.
    It explains how “safe-cache” works.

    Every cache file has two companion files (WLock and RLock).
    All flock requests are blocking except first one (NB WLock).

    • having WLock ensures opportunity for possible generation of fresh cache
    • having shared RLock ensures safe reading from cache file
    • and having exclusive RLock ensures safe writing to cache file

    There are two companion files for only one reason, and that is when new cache is being generated,
    and old cache is not too old(cache time+N is not expired) clients can still use old cache
    instead of waiting for cache being generated.

    Please comment on this scheme and make it simpler if possible.

    cache locking diagram

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary

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.