Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [cache]

A cache is a component that transparently stores data so that future requests for that data can be served faster.

2
votes
1answer
29 views

Using IndexedDB as an in-browser cache

In my site: Users have many Activities Each Activity has encoded_polyline data I display these encoded_polylines on a map I want to use IndexedDB (via Dexie) as an in-browser cache so that they don'...
2
votes
1answer
74 views

Cache with limited size; If full remove the oldest

Here is a class that stores a single value into the limited cache. If cache is full, it will remove the oldest element to make a space for a new value. I'm using 2 structures to accomplish this ...
1
vote
0answers
71 views

Data structure that is fast to read and modify

I'm working on an apllication that needs to process a lot of objects in realtime. I've separated the logic from the UI so that it isn't as much of a mess. The basic idea is that every tick I'm trying ...
3
votes
2answers
76 views

java Thread-safe LRUCache implementation

What is best way to implement thread-safe LRUCache in java? Please review this one. Is there any better approach which can be taken here? ...
2
votes
1answer
56 views

Rust closure to be called on a cache miss

The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash ...
3
votes
1answer
52 views

Cache-optimized matrix multiplication algorithm in C

I am trying to optimize matrix multiplication on a single processor by optimizing cache use. I am implemented a block multiplication and used some loop unrolling, but I'm at a loss on how to optimize ...
1
vote
1answer
46 views

When slide show web page is reopen, the web page loading is very slow

Here is a script that opens about 200 pictures, the first time you open the webpage, loading of the 200 pictures is fast, However if you reopen the page, it takes about 4 minutes to load the same page ...
3
votes
1answer
65 views

Reference service for a cache

I'm using JDK 11. This is my code: ...
2
votes
0answers
29 views

Caching different http-requests

There have been multiple discussions on caching http-requests with RXJS. In this question/proposal I want to propose a custom rxjs-operator (non-pure) to provide ...
3
votes
0answers
73 views

Iteration of self-refreshing MemoryCache encapsulation

I have attempted to implement the advice from the original post and debugged the original concept. Certain changes in the logic have necessitated other changes, including breaking into the library ...
2
votes
1answer
51 views

Long cache refresh with guaranteed response

I am trying to ensure that (once a cache item is populated) even if it's refresh object takes a long time to retrieve, the original cache item can be requested. ...
1
vote
1answer
42 views

Generic Cache-Aware Data Adapter

I've written a generic data adapter that can make use of a cache, for use in a data access layer. It presents an interface allowing CRUD operations, as well as retrieving all objects of a certain type....
2
votes
1answer
129 views

LRU Cache in C++11

This is a simple and robust LRUCache implementation using doubly linked list and unordered map. It supports .get(), .put(), and <...
0
votes
1answer
59 views

Minimum steps to reach target by a Knight In Scala

Given a chessboard of N size (square matrix), the position of Knight and position of a target, find out minimum steps (both count and exact steps) from start to target for a Knight. If it is not ...
2
votes
0answers
42 views

Implementing key map with expire and size limit

Recently I have been asked to implement a key map with expire time for each key and possibility to limit the number of keys, in Python. I've used a dictionary + heap to store the entries, e.g.: ...
1
vote
0answers
45 views

Design a system for renting digital movies/books

During an interview I was asked to do an OO design for a digital renting system for books/movies. This is the design that I came up with. My assumptions: When the customer has downloaded a list of ...
2
votes
1answer
148 views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
0
votes
0answers
39 views

Using ReadWriteLock to implement a cache access guard

In my project, there is an internal cache api to use. I have noticed an emerging pattern such that: ...
2
votes
2answers
172 views

Simple implementation of LRU caching in PHP

This is my implementation of LRU caching in PHP. It works fine when I tested as. What are the things that I miss or need attention? ...
1
vote
2answers
88 views

DataService that fetches data not loaded already or loads cached values

I load an array from an API that is available throughout the user's whole session. This data is unlikely to change, so it can be cached safely. I have a DataService ...
0
votes
2answers
491 views

LRU Cache in constant time

I would like to ask for code review for my LRU Cache implementation from leetcode. Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...
6
votes
0answers
72 views

Resource cache based on Stroustrup 22.2.4

I recently read "The C++ programming language" chapter 22 and I thought the example given in chapter 22.2.4 was quite interesting. I thought it should be possible to make this system caching, so it ...
4
votes
2answers
254 views

Thread-safe cache using a linked list

Are the final templated functions allocate and deallocate thread safe? The Cache object is a ...
4
votes
2answers
115 views

Fetching data through HTTP and caching JSON result in a file

The task is to fetch some JSON data from an API with a GET request. If the location is not available for any reason, read a cache file. Otherwise write the cache file for future use. The following ...
3
votes
1answer
91 views

Custom caching class in Swift

I'm using Swift 4.0 and I'm using UserDefaults in my project for storing Strings like login or something. I have a class: ...
2
votes
2answers
127 views

C++ Software cache for shared resources

I wrote a basic C++ template to manage shared resources like textures and shaders in a 3D engine. The idea is that the cache itself holds weak references to the resources (through ...
2
votes
1answer
77 views

Least recent use cache in python

Below is LRU Cache class implementation. ...
0
votes
1answer
57 views

Maintaining a temporary directory

I have this class/service, which I need to maintain. Its purpose is to manage a temporary directory so that all content can be deleted on next restart files are not left behind when you're done with ...
1
vote
1answer
269 views

Cached Repository that can refresh all or a subset of the data

IReadOnlyCachedRepository<T> ...
6
votes
1answer
100 views

Simple time-bound cache

In my project i should cache some items (1 - 1000) in one time. Item should be removed from cache after 5 minutes by last access to cached item. Better use community libs, or standart mechanisms (...
4
votes
3answers
739 views

Thread-safe LRU cache

Please review my code. I am trying to implement a thread-safe LRU cache using std::list and std::unordered_map. This is a header-...
3
votes
1answer
1k views

Memory cache implementation with a static class inside a normal class

I'm trying to implement a cache available in a data provider (repository). The data provider is a normal class, instanciated at every request made to the application. The reason I have a static ...
11
votes
3answers
2k views

Implementation of LRU cache

What do you think of this implementation of an LRU cache? I'm trying to migrate to modern C++, so it would be fantastic if you could give me any tips here. I've heard it's not desired to use raw ...
4
votes
3answers
155 views

Caching an integer - distinguishing no value from zero

I would like to store an integer value in the application cache. The GetOrSet method should always return an int, and never be null. If there is no cached value, ...
1
vote
1answer
1k views

Changing object attributes by calling getters and setters using reflection

We have a class with 10 attributes (longs, Strings) the following method should change any attribute to any value of an object specified by the client, It mimics the SQL update statement ...
0
votes
2answers
100 views

Create another Singleton object from a Singleton class

I want to create a singleton object of a third party caching library (ThirdPartyKVStore). But I don't want to reference this class all over the place from where I ...
2
votes
1answer
134 views

Stack for asynchronous processing

The following TaskStack processes input elements asynchronously based on a function that it receives at construction: ...
3
votes
1answer
73 views

Speeding up evaluation of power series, Python

I want to plot (on the complex plane, with mpmath) the power series whose general term is the number of partitions of an integer. The more points I want (and the ...
2
votes
2answers
386 views

Simple yet threadsafe file cache in java

I'm attempting to cache contents of a file to avoid frequent reads, using a very simple implementation in a single class. The file contains a list of emailids, one per line. The file changes rarely, ...
3
votes
1answer
168 views

Cache friendly string

Suppose you have a vector or list from the following: struct Data{ std::string key; //... }; When you do some processing, when you compare the key, it ...
1
vote
0answers
102 views

Service Worker fetch handler with promise race code

Some combinations of older hard drives, virus scanners, and faster internet connections, getting resources from the network can be quicker than cached content on the user's disk. Looking for a way ...
-1
votes
1answer
772 views

C# implementation of LRU-cache

I implemented a LRU-cache in C# and wanted to hear suggestions in making it more readable and maybe even more compact. ...
9
votes
2answers
4k views

LRU cache implementation

I have implemented an LRU cache, the question is taken from: leetcode: 146. LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...
1
vote
1answer
826 views

CacheManager - Dependency injection

I create a cache manager to manage a system of cache exchangeable by another implementation. I use the CacheManager class throughout my program. If I want to ...
3
votes
1answer
2k views

LRU cache implementation in C++ using unordered_map and doubly linked list

I have implemented an LRU cache in C++ using a hash table and a doubly linked list. Any kind of feedback is appreciated. ...
4
votes
1answer
515 views

Sequence cache with TTL expiry

I've had some fun writing a sequence based cache that is going to be used to maintain a consistent stream withstanding network re-connections. The idea is that subscribers of a network based stream ...
4
votes
2answers
3k views

Rest API for realtime statistics of last 60 seconds

The following code is my solution to a code challenge I submitted a few weeks ago. I got rejected straight away with no feedback and I've wondering why. I'm interested in hearing if there is any ...
4
votes
2answers
91 views

C daemon to perpetually cache data from an external API

Background My task is to create a program to continuously download utility meter data from an external API, and cache it in a MySQL database for faster access. The performance of this program is ...
9
votes
2answers
859 views

Memoizing or caching Bash function results

Update: I've implemented several of the features suggested below and packaged the improved code into a dedicated project: bash-cache . I display a number of expensive operations in my Bash prompt (e....
3
votes
2answers
147 views

ConcurrentHashQueue in C#

The ConcurrentHashQueue data structure is a FIFO queue that at the same time allows look-ups of items based on a key in O(1) like a dictionary. It can be used as a ...