Contents tagged with Cache

  • My "Ah-Ha!" Moment With LINQ

    I'm currently working on a set of web services that will be consumed by iPhone and Android devices. Given how often the web services will be called in a relatively short period of time, the data access for the web services has proven to be a very important aspect of the project. In choosing the technology stack for implementation, I opted for LINQ to SQL as it was something I had dabbled with in the past and wanted to learn more about in a real environment. The query optimization happening behind the scenes was something that I had an appreciation for.

    Once I completed the implementation of the web services we noticed a performance bottleneck on one of the calls. LINQ to SQL was doing all it could to help us in this situation but the nature of the required response was simply too heavy on the database to expect any real performance from any query. We ended up being able to cache the data we were querying against which would help tremendously.

    What I was expecting was a large re-write of code to accommodate my new source of data. Instead, using LINQ, I was able to simply change the from statement in my LINQ query and get the results I needed. Essentially, when building the cache, I create a List collection for the objects I'll need to query against and subsequently return to the mobile device. The results of that general query are stored in cache. When I need to perform a query against that cached collection, I have a LINQ query, which I used previously to query the database tables, that now uses the cached collection as it's data source. Which is really a fancy way of saying the "from" statement in the LINQ query. There were no ugly nested loops with various comparison statements needed.

    Going from querying a database to querying a local in-memory collection was beyond trivial with LINQ. After getting it up and working, I fell back into my chair in amazement.