How long does AngularJS cache $http requests for?

Hey there! According to my understanding of the Angular documentation, this is how you can set the cache for an $http request:

cache – {boolean|Cache} – If set to true, a default $http cache will be used for caching the GET request. Alternatively, if a cache instance has been created using $cacheFactory, that specific cache will be used.

So, by setting {cache:true}, I'm wondering how long the request will actually be cached for?

Is it possible to specify the maximum time for caching in some way?

Answer №1

When it comes to caching, this system stores the data until there is a change in the full html site. For instance, in a regular SPA, the data remains in cache for the entire lifetime of the app. There isn't a built-in method to establish a maximum cache time. If you want to clear the cache, you will need to do so manually.

var cache = $cacheFactory.get('$http');
cache.removeAll();

To learn more about the $cacheFactory, visit: http://docs.angularjs.org/api/ng.$cacheFactory

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

Unlocking the power of module augmentation in Typescript: Enhancing library models within your app domain

I currently work with two applications that share the same code base for their models. I am interested in developing and sharing a library model using inheritance in TypeScript. For instance, Pet extends Author. In my current Angular application, I need ...

Launching ExpressJS and ReactJS on Heroku

Currently working on a project that combines express and react. When attempting to deploy it to Heroku via git push, I encountered an error upon checking the heroku logs. The specified webpage then shows a message indicating that it cannot locate a build ...

Once map layers have been loaded initially, they will not render again

I'm currently incorporating Mapbox GL into my Vue project using VueMapbox (0.4.1). <template> <MglMap :accessToken="accessToken" :mapStyle.sync="mapStyle" :repaint="true" @load="onMapLoaded ...

The functionality of the delete button in Datatables is only operational on the initial page, failing to

My datatable is giving me trouble. The delete button in the action column only works on the first page, but not on the other pages. Here is the code for my delete button: <table id="example" class="table table-striped table-bordered" cellspacing="0" wi ...

I am experiencing difficulties connecting my webRTC app to the remote system

I've set up my webRTC app on an HTTPS server and it's working fine. However, I'm facing an issue where the Remote system details (SDP) are not being captured. Both the Local system (PC1) and Remote system (PC2) are unable to establish connec ...

The misleading A*(A-star) algorithm inaccurately produces faulty routes and ultimately collapses

I am currently working on implementing the A*(A-star) algorithm in react.js, but I am facing a problem. Whenever the startNode (green) or destinationNode (blue) have more than one neighbour or if there is a cycle in the graph, my program crashes. There see ...

Enhance your Vue app with filtered categories using Vue-google-chart

What is the process for creating a filter category in a bar chart using the vue-google-charts wrapper in Vue.js? I have successfully created a stacked bar chart and now I am looking to add a filter by label inside the legend. Here is my vue application: ...

Steps to create a function that repeats a specified number of times as chosen by the user from a dropdown menu

I have encountered a challenge involving running a function multiple times based on the user's selection of a number. My JavaScript code is quite lengthy with nested functions, making it difficult to make significant modifications. Here is a simplifie ...

Significant increase in response time observed after 3 minutes of inactivity on the Web API

I've encountered a peculiar issue in both my preproduction and production environments (but not in development). My website performs various operations on a Web Api that is hosted on the same IIS server. Typically, a specific POST request is process ...

Mocking a dependency in Jest that is initialized prior to exporting the module

I'm currently in the process of testing a file that exports a single default function and also needs to create an object prior to exporting the function. It's crucial for this object to remain constant and be the same instance every time the expo ...

python selenium web scraping element not found error

While learning about web crawling using selenium, I encountered an error. Here is my code: from selenium import webdriver as wd main_url = 'https://searchad.naver.com/' driver = wd.Chrome(executable_path='chromedriver.exe') After log ...

Learn how to use AngularJS with the Angular UI router to seamlessly fetch new content via AJAX without disturbing the existing content on the page

I've integrated Angular UI Router into my application and here's what I'm currently working on. The main view consists of a child view along with a div container for "pagination" Initially, a first set of contents is loaded by default When ...

How can I effectively update my Vue.js component for optimal performance?

I have a search page with a text box and search button. I implemented a facet using Vue.js. Initially, everything works fine when I search for something. However, after typing a new text and searching again, the facet does not update with the new values. ...

Is there a way to display the back and forward buttons on a popup window opened through window.open or self.open in Chrome browser?

When I try to open a popup window using the code snippet below, I am facing some issues. self.open('myJSPPage','ServicePopUp','height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes'); Afte ...

text field remaining populated

I have a form where the input fields clear when they are clicked on. It works well on most pages, but there is a specific type of page where it is not functioning properly due to the presence of another javascript running. - issue observed // On this pa ...

Avoiding the default action to submit AJAX form data won't result in any changes to the front end?

Currently, I am working with Flask and have utilized JavaScript to prevent default behavior in order to send all the necessary data through an AJAX request. However, I am facing an issue where although my view contains all the data (verified by console out ...

tips on adjusting margins or paddings in option select

How can I use the margin or padding options for my select dropdown? I tried using &nbsp; <select class="select"> <option value="100"></option> <option value="250">$593</option> ...

What is the best way to store font size and background color settings in local storage?

After following the solution provided for a similar issue on SO, I am facing a problem where no changes are reflected when using the select box or color picker to modify the font size or background color. I have commented out the lines that were added in a ...

Enhance conditional attributes for Meteor user sessions

Currently working with Meteor alongside Iron-router. I've recently made adjustments to be compatible with the 0.8 update, but I'm encountering some challenges. Instead of embedding conditional attributes within a div in HTML, I have transitioned ...

The art of slipping away from a character in JavaScript while adding HTML using jQuery

I am trying to add multiple HTML canvas elements to an existing HTML canvas. <div> <canvas id="BackGroundImage" width="800" height="300" style="position: absolute; z-index: 0;"></canvas> <canvas id="canvas" width= ...