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 9203105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:23:59+00:00 2026-06-17T23:23:59+00:00

I have a simple Orders service and would like to implement caching. Here’s my

  • 0

I have a simple Orders service and would like to implement caching. Here’s my request/response and service:

[Route("/order", "GET")]
[Route("/order/{Id}", "GET")]
public class OrderRequest : IReturn<OrderResponse>
{
    public int Id { get; set; }

    public string Reference1 { get; set; }

    public string Reference2 { get; set; }

    public DateRange CreatedOn { get; set; }

    public DateRange ProcessedOn { get; set; }

    public DateRange ShippedOn { get; set; }

    public DateRange ModifiedOn { get; set; }
}

public class OrderResponse : IHasResponseStatus 
{
    public ResponseStatus ResponseStatus { get; set; }

    public List<Order> Orders { get; set; }
}

public class OrdersService : Service
{
    public object Get(OrderRequest request)
    {
        var cacheKey = UrnId.Create<OrderResponse>(request.Id.ToString());
        return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, cacheKey, new TimeSpan(0,5,0), () =>
        {
            return GetOrders(request);
        });
    }

    public OrderResponse GetOrders(OrderRequest request)
    {
        ..
    }
}

Looking at the documentation a unique key is generated for each cached item. In the examples this is typically the response object + item id. However I would like to cache different types of request. For instance, in my request I can specify a date range. If I make the same request with the same date range then I would like to receive the cached copy. So my question is, what is the best way to generate a unique id based on some or all request parameters? Perhaps use or override GetHashCode on the request DTO? And secondly, if my cache contained many objects of the same type, i.e. OrderResponse, can I delete all items of a given type? Otherwise if I modify an order i’ll have no idea which of the cached objects to delete.

  • 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-17T23:24:00+00:00Added an answer on June 17, 2026 at 11:24 pm

    There’s nothing special or important about the cacheKey, it just has to be unique for each different item or result-set you want to cache.

    If you want it to support different caches for specified date ranges then the variable information needs to be added to the key. You can either use the combination of unique properties on the Request DTO or if it’s suitable the base.Request.PathInfo and/or QueryString to create a unique string to use as the cache key.

    And secondly, if my cache contained many objects of the same type, i.e. OrderResponse, can I delete all items of a given type?

    No, each CacheProvider is ignorant of what is being cached, the cache invalidation logic is up to the client application to manage.

    Otherwise if I modify an order i’ll have no idea which of the cached objects to delete.

    Right, in which case you either have to put an expiration so it expires itself or make use any advanced features of the underlying cache providers (if they support it). E.g. if you use a MemoryCacheClient supports the wildcard APIs:

     cache.RemoveByPattern("cache:Orders:*");
     cache.RemoveByRegex("cache:Orders:.*);
    

    So if you structure your keys hierarchically using the same prefixes you can invalidate all related caches with a single wildcard command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Service model with title:string description:string date:datetime. I would like to implement
I would like to connect and query Trip Advisor's SOAP service. I currently have
I have created a simple order manager wf service (state machine) in WF4. Order
I'm getting started with FubuMVC and I have a simple Customer -> Order relationship
I have a simple UIView that draws itself using drawRect: . In order for
I have a very simple webforms app that will allow field techs to order
I have a very simple query $this->db->select('id, title'); $this->db->order_by('id', 'DESC'); $query = $this->db->get('journal'); foreach($query->result()
I have multiple views which make the same NSURLRequest/NSURLConnection request . Ideally, in order
I currently have a very simple web application written in Django, and I would
Have simple Order - Item app. No cart. Need help with joined scopes for

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.