Using Angular to store image data with base64 encoding for improved caching efficiency

Imagine I have an application that showcases various restaurants in a specific city. With numerous listings, the data volume is substantial even without including any images.

If I aim to provide users with quick access to this data by implementing caching, my approach involves saving the data using ngStorage. I check for its existence - if present, I retrieve it from $localStorage; if not, I fetch the data from the database and set it in $localStorage.

$scope.Restaurants = {};
if(Object.keys($localStorage.restaurants).length === 0){ 

    $http.get('www.mydata.internet/RESTaurants').then(function(res){ // pardon the pun

        $localStorage.restaurants = res.data.restaurants;
        $scope.Restaurants = res.data.restaurants;

    });

} else $scope.Restaurants = $localStorage.restaurants;

This method works effectively until images stored in the database as base64 are introduced.

Suddenly, the data size grows significantly, causing ngStorage to reach its limit and break. Moreover, downloading numerous images and storing them locally does not scale well.

Nevertheless, I still desire to cache this data to avoid querying the database each time it is required.

Is there a solution to efficiently cache such a large amount of data?

Answer №1

When faced with this particular situation, a myriad of factors come into play.

The first step would be to analyze how the data is being loaded for your application. It is essential to assess if there is a genuine necessity to cache such a substantial amount of data. How many server calls are being made to retrieve the data? Are you fetching all the information at once or in smaller portions?

Furthermore, it is vital to understand whether the data is eagerly loaded, lazily loaded, or a combination of both. Is some basic data requested initially followed by more detailed data loading in the background?

Once these inquiries have been addressed, it is pivotal to evaluate if a large caching mechanism is still indispensable. Perhaps reconsidering the approach to data loading could eliminate the need for extensive caching, or opting for a smaller storage solution like local storage might suffice.

If a larger caching system remains imperative, exploring options to cache data on the server side to reduce frequent database queries could be beneficial. In scenarios where substantial amounts of data, including images, need to be cached client-side (in the browser), ponder storing images as blobs using technologies such as IndexedDB.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React: Conceal additional elements once there are over three elements in each section

React: I am trying to create a menu with submenus. My goal is to calculate the number of submenus and if it goes over 3, hide the additional submenus. Below is the code snippet for counting the elements: export default function App() { const ElementRef ...

Creating a canvas texture on tube geometry with three.js for optimal display on iPad devices

I have a 3D model of a tube geometry with 18000 coordinates on the production side. To simplify, I am selecting every 9th coordinate to plot 9000 coordinates for building the tube geometry using only the CanvasRenderer. When utilizing vertexColors: THREE. ...

What are some ways to manipulate JSON data following a successful AJAX request?

I've been grappling with this issue for quite some time now, trying various methods without any success. I won't bore you with the details of my failed attempts, but instead, I'll show you the code I'm currently working with. Here' ...

What methods does Javascript callback employ to access an external variable that has not yet been defined?

Hi all, I am a beginner in nodejs and recently stumbled upon this function within express var server = app.listen(()=>{ console.log(server.address()) }) I'm curious about how the callback utilizes the object that is returned by the listen func ...

I am currently working with an input element that is set to hidden. I am trying to change its type to text using JavaScript, but I can't seem to figure out how to do it or if it is even possible

I'm stuck trying to change the type of an input element from hidden to text using JavaScript. I can't seem to figure out if it's even possible. Can someone please help me with this? Thanks! ...

Provide users with the option to select a specific destination for saving their file

In the midst of my spring MVC project, I find myself in need of implementing a file path chooser for users. The goal is to allow users to select a specific location where they can save their files, such as C:\testlocation\sublocation... Despite r ...

Transmit the bound data (using ng-model) to a custom AngularJS directive

/*I am looking to define the maxDate as vmEndDate*/ app.directive('myDatepicker', function ($parse) { return function (scope, element, attrs, controller) { var ngModel = $parse(attrs.ngModel); alert(element.va ...

Intersecting object identification, fresh Function

I'm currently utilizing the "Sinova / Collisions" library on GitHub along with Node.js. The library can be found at https://github.com/Sinova/Collisions. I am in need of a function that allows me to delete all data at once, as the current function for ...

How can I effectively separate the impact of Next.js onChange from my onClick function?

The buttons in my code are not functioning properly unless I remove the onChange. Adding () to my functions inside onClick causes them to run on every keystroke. How can I resolve this issue? In order to post my question, I need to include some dummy text. ...

Optimal Timing for Loading Initial State from Database Using Vuex

In my Vue/Vuex project, I have a simple setup where I retrieve a list of categories from my database using an HTTP GET request. Before implementing Vuex, I used to fetch this data directly in my main component when it was created. Now with Vuex, I have g ...

Is it necessary to make a distinct route for SocketIO implementation?

I am new to Socket.IO and I recently completed the chat tutorial in the documentation along with some additional tasks to gain a better understanding of how it works. Currently, I am attempting to establish a connection between a NodeJS server and a React ...

Improved method for categorizing items within an Array

Currently working on developing a CRUD API for a post-processing tool that deals with data structured like: { _date: '3/19/2021', monitor: 'metric1', project: 'bluejays', id1: 'test-pmon-2', voltageConditio ...

Attempting to connect JQuery to a different page through a data attribute connection

I am currently working on a slider that connects slides from an external page through data attributes. Here is the setup: Main Page <div id="sitewrapper"> <section class="sliderwrapper"> <div id="slider" data-source="slides-pa ...

Showing a DIV multiple times with an additional text field in HTML and JS

As someone new to development, I am facing a requirement where I need to create a form with a dynamic field that can be added or removed using buttons. When the user clicks on the Add button, another field should appear, and when they click on Remove, the ...

Layer one image on top of another using z-index

I'm having trouble layering one image on top of another in my code. Here is my code: body { background: #000000 50% 50%; height: 100% width:100%; overflow-x: hidden; overflow-y: hidden; } .neer { z-index: 100; position: absolute; } ...

Utilizing React JS to neatly display Firebase data in a table

Before I post, I always make sure to do my due diligence by searching on Google, YouTube, forums, or trying to figure it out on my own. I even check questions similar to mine asked by other people, but unfortunately, I'm stuck. Currently, I am using ...

What could be causing JQuery to disrupt my HTML code by inserting additional <a> tags?

My dilemma involves this specific chunk of HTML code stored within a javascript string, while utilizing Jquery 1.6.1 from the Google CDN: Upon executing console.log(string): <a><div class='product-autocomplete-result'> & ...

Is Angular capable of displaying a date within a specific timeframe using ng-show?

So I have a button that, when clicked, displays a list of data. I am adding a unique font awesome icon in there if the JSON key value exists. However, here lies the issue. The particular key happens to be a date. I need my ng-show function to check whether ...

Angular and JavaScript: Today is Monday and the date is exactly one week old

I am currently working on an Angular application that is connected to a REST API. In order to minimize the number of requests made, I have implemented a method to store all data in the local storage. .factory('$localstorage', ['$window&apos ...

Saving a single ID at a time in a UseState array by clicking in ReactJS

When clicking on the "click here" button, I am trying to save favorite post IDs in an array. However, the issue is that it is currently only saving one ID at a time in the array. Every time you click on another "click here" button, it removes the previous ...