Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:30:49+00:00 2026-06-14T22:30:49+00:00

I send three http requests to a web service every 10th second. The reponses

  • 0

I send three http requests to a web service every 10th second. The reponses are handed off to three methods in a cache class (one for each http query / request) that checks whether the reponse content has changed since last time.

I convert the raw reponse content to a string and compare it to the old response, which is stored as a private string in the cache class. It works alright, but the approach has a lot of duplicate code, as you can see:

    class Cache
{
    private HubClient _hubClient;
    private string oldIncidentAppointment;
    private string oldIncidentGeneral;
    private string oldIncidentUntreated;

    public Cache(HubClient hubClient)
    {
        _hubClient = hubClient;
    }

    public bool IsIncidentAppointmentNew(string currentIncidentAppointment)
    {
        if (XElement.Equals(oldIncidentAppointment, currentIncidentAppointment))
        {
            return false;
        }
        else
        {
            oldIncidentAppointment = currentIncidentAppointment;
            _hubClient.SendToHub();
            return true;
        }
    }

    public bool IsIncidentUntreatedNew(string currentIncidentUntreated)
    {
        if (XElement.Equals(oldIncidentUntreated, currentIncidentUntreated))
        {
            return false;
        }
        else
        {
            oldIncidentUntreated = currentIncidentUntreated;
            _hubClient.SendToHub();
            return true;
        }
    }

    public bool IsIncidentGeneralNew(string currentIncidentGeneral)
    {
        if (XElement.Equals(oldIncidentGeneral, currentIncidentGeneral))
        {
            return false;
        }
        else
        {
            oldIncidentGeneral = currentIncidentGeneral;
            _hubClient.SendToHub();
            return true;
        }
    }
}

How can this be refactored into a generalized method that compares old and new content for all my current and future http query methods?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:30:51+00:00Added an answer on June 14, 2026 at 10:30 pm

    You can store them in a dictionary:

    class Cache {
    
        private HubClient _hubClient;
        private Dictionary<string, string> _pages;
    
    
        public Cache(HubClient hubClient)
        {
            _hubClient = hubClient;
            _pages = new Dictionary<string, string>();
        }
    
        public bool isPageNew( string key, string content ) {
            string current;
            if (_pages.TryGetValue(key, out current) && XElement.Equals(current, content)) {
                return false;
            }
    
            _pages[key] = content;
            _hubClient.SendToHub(); //Why have side effect here? :P
            return true;
        }
    }
    

    Then:

    Cache cache = new Cache( client );
    
    if( cache.isPageNew( "untreated", pageContent ) ) {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to send three asynch requests in three class files, 3 requests response
Create a web service on http://www.a.com/service.asmx and send a cross-domain ajax request to it
I have a web service which requires me to send file data to HTTP
I have 2 different XMLHttpRequest objects making asynchronous requests to the same web service.
When I send a request to my web-service with utf-8 special characters, such as
I am trying to send a request to a web service. The wsdl can
I'm having some problems understanding how to send a request to a web service
I’m working on a Python app that needs to send hundreds of HTTP requests
I am trying to implement a web service that accepts SOAP 1.2 over HTTP
I know that soap can send XML over http, is there any way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.