2

I have thousands on records in MS Sql server database table, to get it search it quickly on web page I created WCF REST service that returns List of records fetched from database by keywords converted into JSON and get displayed in DIV just below html textbox in html page. (like google search textbox).

I used server side cache object to avoid database hit upto some extent. But I am forced to hit REST GET url on every text change.

Any suggestions to make it faster?

  • Cache on client side and only go to the server if the query gets less selective? – TZHX Oct 23 '15 at 06:16
  • Thanks, I am trying this, but subsequently this will make cache increase at client and client can see whole of records. – Vishwanath Mishra Oct 23 '15 at 06:31
  • Upto some extent performance increased but I don't think it make any sense save database records at client side and it will be client specific. – Vishwanath Mishra Oct 23 '15 at 09:14
  • A thousand records seems like a fairly small table. Even naive strategy should work fast enough for database of this size, unless you have extremely complex joins on your queries or huge text blobs. If you have huge text blobs in your tables, then you might want to explore full text indexing. If you have complex joins, then there may be options you can do to speed up the query. – Lie Ryan Oct 23 '15 at 12:53
  • If round trip is your bottleneck, then you'd definitely want to reduce the number of queries you make to the server. Instead of doing thousands of small queries, do a few larger queries instead. Also paginate whenever you have an API that returns a list of items. Without example queries, it's hard to give specific advice, can you post some example queries from your existing application here? – Lie Ryan Oct 23 '15 at 13:05

2 Answers2

1

There can be a way to reduce your REST calls. There are techniques available for client side caching which allows to cache the ajax responses so that next time if same request is repeated the results are produced from cache. But you have to Very Careful using such techniques as it may be endup giving wrong results and behavior.

See this answer. It is similar to your question but the discussion is really interesting which will give you insight of client side cache implementation to reduced Ajax call round trips.

Community
  • 1
  • 1
vendettamit
  • 14,315
  • 2
  • 32
  • 54
0

As you're using a Rest, you're making a http request to your service. You can take advantage of the Output Cache of ASP.Net.

The call will hit the server, but it will automatically response your request without running the code.

You do it like this:

[AspNetCacheProfile("CachePoliceName")]
    [WebGet(UriTemplate = "{userName}")]
    public String GetData(string parameter)
    {   // your code }

If requered, you need to enable AspNet compatibility in your configuration file:

<system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />    
</system.serviceModel>

See more here: https://msdn.microsoft.com/en-us/library/vstudio/ee230443%28v=vs.100%29.aspx

And here: http://blogs.msdn.com/b/endpoint/archive/2010/01/28/integrating-asp-net-output-caching-with-wcf-webhttp-services.aspx

Hope it helps.

Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43