How to cache multiple version of site

I have a site with feed of user notes, and i want to show to users only top 100 notes (paginated by 10 per page). Every note has some tags (like subreddits on reddit), and every user can add some tags to black list to don’t see notes with this tags. I have a problem because if all of top 100 notes has one tag from blacklist then user see no notes. I don’t want to generate page for user because is expensive, so i am looking for smart way to cache multiple version of site.

I tried: – get top 1000 and cache and filter value from cache per request – build cache key with user blacklist – every user can have different black list so i can cache it for user – not good – get top5 tags from last hour and build from it all combination and cache every combination, and check which combination match the best for user – it’s not good idea because there is so much tags, and calculating top X it isn’t cheap, and top 5 can be too least

Direct-mapped cache and 2-way set-associative cache – what type of division do we use?

I’m trying to solve the following problem:

We have a CPU with 32-bit address space in memory and we are trying to speed up the data access using 1MB cache with address length of 64 bytes. What type of division of 32 bit address (tag, index or offset) do we use, if cache is of type:

a) direct-mapped cache

b) 2-way set-associative cache

Can you help me any way? I don’t know which type of cache use what division. Thanks!

How to use file system as cache for products which are expensive to produce?


The consumer client components consume files. They access files in two step:

  • Clients call a REST API with a parameters what they want, and the API responds with a file path.
  • Clients access to the file using file system access.

There are two contradicting constraint: Producing the files has high cost, and takes time, so on demand production them is not an option. However it can be predicted all files will not fit on the storage, there will be more.

My first thought is to start with producing and storing the files, (and serve if there is a request using the API described above), and if the storage is near full the API detects, and starts deleting the less demanded files (based on a strategy, which is out of topic). In case if a file is requested and not on the filesystem yet, produce, store and respond with the path.

So it seems it is a file product cache on the file system.


Is there any open source component which fits to this scenario, of do I have to implement myself?


I have created an android app which, upon clicking it, simply opens up a website in the browser. Around 10,000 people (same 10k people) daily open this application once to see the website homepage. (I update some content daily on the homepage). The problem is, I only edit a few lines of text that appear on the homepage. Rest everything including bg image and other stuff remains as is. So when a new person will first open the application, the stuff like bg image and other bootstrap/css files of the website should get stored in the cache memory, so that when the same user again opens the app, most of the files should get fetched from the cache and not from the server. I have hosted the site on AWS. (The link is The website is static, and whole website size is about 4 mb including all css/html/js/bootstrap files and images that make up the website. When I check the daily data usage stats on AWS, it shows that around 2.5 Gb data bandwidth is being utilized daily. The same 10K people visit the website daily. I don’t understand this. After most of the data of the site gets stored in the cache for a fresh visitor, the amount of data consumed per person should then be around 1kb daily afterwards and not more. How come 2.5 Gb data is being used daily ? Is there some fault with the app ? I suspect the app is not storing the data in cache and is fetching the data everytime from the server. Please guide me where I am wrong. The monthly data consumption for such a simple website with the same 10K people visiting it daily should not exceed even 10 Gb per month, while in my case data consumption is about 75 Gb per month. Any help would be appreciated. Thanks in advance.

Set Associative Cache Exercise

I am new to cache and I am trying to figure out how to solve this problem. Can someone please provide me with some materials that would help me solve these types of questions? I tried googling Set Associative Cache but did not find a lot of sources on the topic.

Can someone also guide me towards how I could solve this question?

2 Set Associative Cache

Assume the following content of a cache memory in which all blocks are valid. Two way set cache (m=2) is byte oriented with the block size 16 bytes.

Determine the content of 8-bit data bus in case that the processor performs the reading and the value B70A occurs on the 16-bit address bus. If the Requested data is not present in the cache memory then cross out all the former data within this memory which will be overwritten as a result of storing new values.

In such case write on the data bus the letter and determine new values of the LRU and the KEY. (Note: Numbering of data columns: 0… left column, 1… right column.)

Required Information:

  • Data bus content:
  • New value of the LRU:
  • New value of the LRU in raw no:
  • New value of Key:
  • New value of Key in column no:

enter image description here

Installing MongoDB on RHEL 8 | AWS EC2 — Failed to synchronize cache

I am attempting to install MongoDB on my RedHat 8 | AWS EC2 instance …


[mongodb-org-4.0] name=MongoDB Repository baseurl=$  releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey= 

Then … yum repolist

MongoDB Repository                                                                                                                                                                 366  B/s | 390  B     00:01 Error: Failed to synchronize cache for repo 'mongodb-org-4.0' 

Possibly RHEL 8 being a new release is causing issues?

AWS | RHEL 8 | Failed to synchronize cache for repo ‘mongodb-org-4.0’

I am attempting to install MongoDB on my RedHat 8 | AWS EC2 instance …


[mongodb-org-4.0] name=MongoDB Repository baseurl=$  releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey= 

Then … yum repolist

MongoDB Repository                                                                                                                                                                 366  B/s | 390  B     00:01 Error: Failed to synchronize cache for repo 'mongodb-org-4.0' 

Possibly RHEL 8 being a new release is causing issues?

How to cache static content with a certain condition

I am using Apache httpd to front end a few application servers (eg, WebSphere, JBoss etc). I am also using Apache to cache the static content like gif, jpg, css etc. This works fine for most applications.

However, for a few applications, some of the static content is generated on the fly on the back-end application server. Hence the above procedure fails to work for these applications.

Can I setup Apache httpd such that it serves static content if it finds it on Apache httpd but if a 404 is returned it passes the request to the back-end application server ?

Possible bug in and handling of getOrigData when updating tier prices, goes away when cleaning the cache

We are on Magento 2.2.8 and I was debugging the following issue for hours:

When sending a product-update via the REST API, we were getting

Unique constraint violation found 

for a request as simple as


Request body:

{"product": {"sku": "B1234","customAttributes": [{"attributeCode": "meta_keyword","value": "Bälle"}]}}} 

The big problem is, that I cannot reproduce it using the Production Database Dump locally.

It seems to be strongly related to products which have a tier price in the database (which I am not updating in the REST call).

Luckily I was able to reproduce it somehow on a staging instance on the same machine as production and trace there error down to

vendor/magento/module- catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php 

There is the following code

        // prepare original data to compare         $  origPrices = $  entity->getOrigData($  attribute->getName());         $  old = $  this->prepareOldTierPriceToCompare($  origPrices);         // prepare data for save         $  new = $  this->prepareNewDataForSave($  priceRows, $  isGlobal);          $  delete = array_diff_key($  old, $  new);         $  insert = array_diff_key($  new, $  old);         $  update = array_intersect_key($  new, $  old); 

Using var_dump-driven development techniques I was able to see, that $ old is empty even there IS a database row for the tier price.

Actually the whole getOrigData() is empty.

That causes having $ insert a value which IS already in the database

So MySQL (MariadB) throws an error at the following insertValues call, which tries to insert the already existing value.

        $  isAttributeChanged = $  this->deleteValues($  productId, $  delete);         $  isAttributeChanged |= $  this->insertValues($  productId, $  insert);         $  isAttributeChanged |= $  this->updateValues($  update, $  old); 

This is the error:

 "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '19211-1-0-10.0000-0' for key 'UNQ_E8AB433B9ACB00343ABB312AD2FAB087', query was: INSERT INTO `catalog_product_entity_tier_price` (`entity_id`, `all_groups`, `customer_group_id`, `qty`, `value`, `percentage_value`, `website_id`) VALUES (?, ?, ?, ?, ?, ?, ?)" 

Now the interesting part: If I clean the Magento cache, the problem disappears. For a while. But after another while seems to / might happen again.

Did anybody see such behavior before? Should we just refactor the core to not be so dependent on getOrigData?

EDIT The bug can be reproduced after some time again. Clearing the cache then fixes it. For now I stored the redis cache in a backup and will try to reproduce the issue locally by loading that cache.