"Prior to caching, angular-cache manipulates ng-resource's transformResponse function

Recently, I started utilizing angular-cache and stumbled upon this question on stack overflow. The user was inquiring whether the ngResource transformResponse function is executed before caching. It turns out that it isn't.

However, is there a workaround for this limitation? When my API responds with an object containing excessive information that I don't need for caching purposes, how can I extract only the IDs I require?

My idea is as follows:

app.factory('Operator', function($resource, API_CONFIG_URL, CacheFactory) {
    var opsCache = CacheFactory.get('manageableOperatorsCache');
    return $resource(API_CONFIG_URL+ '/operators/:id', {id: '@id'}, {
        'get': { 
           method:'GET', 
           transformResponse: function(data, headers) { 
              // Transforming the object into this format: ids: [1, 2, 3]
           },
           cache: opsCache
         },
    });
});

Thank you for your assistance :)

Answer №1

To address this issue, I manually fill the cache using CacheFactory.put(key, value) within the transformResponse function

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

Adding information to a designated included component (Angular)

I am trying to develop a directive for generating multiple choice activities. The concept is that within my scope, I hold a model containing an array of questions structured like this: function Controller($scope) { $scope.activity1 = { "questions" ...

What is the best way to handle authentication tokens in a Node.js server application?

One challenge I'm facing is calling an API that requires a token to be passed, and this token needs to be refreshed. The main issue is - How and where should I store a token on the server? Some solutions on the internet suggest doing something like th ...

Is it possible to capture and handle browser-specific errors that occur during an AJAX call? I am having trouble locating and capturing these errors

My goal is to thoroughly test an AJAX call for potential errors by deliberately breaking it in various ways. The error callback in jQuery ajax does not provide detailed information like what the browser logs, which is what I need to capture. For example, C ...

What is the process for adding a highlighted area beneath a curve on a high chart?

I am working on creating a high chart with Angular 4 and I have a specific requirement to highlight certain portions of the Highchart. For example, in the image: In the image above, if a data point value drops below a certain limit (such as 0), it shoul ...

Unable to retrieve coverage report using rewire and cross-env

My challenge lies in obtaining the coverage report using nyc, which works flawlessly without the cross-env plugin. cross-env NODE_ENV=test nyc mocha --ui bdd --reporter spec --colors --require babel-core/register tests --recursive When executing this com ...

Unfortunately, CSS3 PIE is not compatible with border-radius and box-shadow properties

I created a basic HTML/CSS code for testing purposes, but I'm having trouble getting the library to function properly. I've placed the .htc, .php and .js files in the same directory as index.html, but it just won't work. Check out the code ...

When should separate controllers be created for a list of values in a Laravel REST API?

Imagine I have a straightforward API for user registration. This API collects basic information like Name, email, state, gender, and marital status for each user. I already have database tables pre-populated with ids for state, gender, and marital status o ...

Triple the Charts: Highcharts Vue Component combines three dynamic charts into one powerful visual tool

looking for help with creating a complex chart Hello, I have a task of creating what seems to be 3 charts in one design. I am able to create the two scattered charts, but the column charts are proving to be challenging. Thanks to Wojciech Chmiel, I manage ...

`ACCESS DENIED: Unauthorized access attempt detected in Node.js``

When attempting to connect, MySQL is establishing a connection with an unfamiliar IP address. Refer to the code below: .env MYSQL_HOST=domain.example.com MYSQL_USER=**** MYSQL_PASSWORD=**** MYSQL_DB=**** MYSQL_PORT=3306 connection.js const mysql = requir ...

Refreshing a webpage with JavaScript directly from the server (2021)

Utilizing Javascript, I have successfully implemented a cookie setting feature that allows users to switch between normal and classic theme versions on my website by clicking a checkbox. The backend of my application is powered by PHP. My goal is to access ...

How can the dot badge in Material-UI be enlarged?

I'm in need of a badge component that serves as an indicator without displaying any values. I opted for the dot variant, but it's too small for my liking. I tried modifying it with CSS, but it doesn't seem to be working as expected. Any sugg ...

Get the color at a specific index in a JavaScript array

When I click a button, a pie chart is generated using chartjs. The results are displayed based on the filters applied, showing (Name | Value%): Service_1 | 10 Service_2 | 15 Service_3 | 75 Sometimes, certain results may not appear: Service_1 | 20 S ...

What could be the reason for my regex succeeding on the client side but failing on the server side

I have implemented a regex pattern to validate usernames, ensuring they only contain English letters, numbers, and underscores. The client-side code works perfectly, preventing any input other than these characters: <input type="text" name ...

Comparing two arrays in Javascript to find identical values

I am faced with a challenge involving three arrays. One array contains static values, another array contains dynamic values, and the third array is intended to store values that are present in both of the other arrays. My goal is to iterate through the ar ...

"Triggering a key press event for a selected item in a single

Is there a way to automatically add the selected value when the enter key is pressed on a chosen jQuery single select? I am looking for an event similar to keypress that can be used to trigger an action when the return key is pressed. <select id="mys ...

I attempted to upload an image using the Google Drive API, but encountered an error in the response

I am attempting to upload an image using the Google Drive API, but I encountered an error in the response message. The error reads as follows: "Failed to load resource: the server responded with a status of 403 ()" ...

Creating UI Bootstrap dropdowns using ng-repeat on the fly

As a newcomer to AngularJS and UI Bootstrap, I am facing an issue with adding dropdowns dynamically using ng-repeat. The main problem lies in the fact that when one dropdown is clicked, it triggers all of them simultaneously. It seems like there is some mi ...

Issue with AngularJS: Controller unable to access property of ng-model object

I am looking to create a reusable controller that can be used by multiple views. This controller will essentially serve as a template. The issue I'm facing is with setting up simple validation. The problem lies in the fact that the properties set in ...

Shifting Vue components within the dom structure?

Whenever I am on a mobile device, I move Vue components higher up in the dom so that I can use absolute positioning without being contained within a relative container. if (this.mobile) { this.$el.parentNode.removeChild(this.$el); document.getElem ...

Continuously improving the form as they evolve

I am interested in creating a form that automatically sends data when users make changes to it. For instance: Imagine a scenario where a moderator is editing an article and changes values in a select field. As soon as the change is made, an ajax request ...