All Projects → VahidN → Efsecondlevelcache

VahidN / Efsecondlevelcache

Licence: apache-2.0
Entity Framework 6.x Second Level Caching Library.

Projects that are alternatives of or similar to Efsecondlevelcache

Ansible Role Memcached
Ansible Role - Memcached
Stars: ✭ 54 (-14.29%)
Mutual labels:  caching, performance
Laravel Varnish
Making Varnish and Laravel play nice together
Stars: ✭ 291 (+361.9%)
Mutual labels:  caching, performance
Trickster
Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator
Stars: ✭ 1,306 (+1973.02%)
Mutual labels:  caching, performance
Awesome Wp Speed Up
Plugins and resources to speed up and optimize your WordPress site.
Stars: ✭ 375 (+495.24%)
Mutual labels:  caching, performance
Scaffeine
Thin Scala wrapper for Caffeine (https://github.com/ben-manes/caffeine)
Stars: ✭ 195 (+209.52%)
Mutual labels:  caching, performance
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+8319.05%)
Mutual labels:  caching, performance
Goldiloader
Just the right amount of Rails eager loading
Stars: ✭ 1,074 (+1604.76%)
Mutual labels:  performance
Performance Column
🚅 性能专栏(Performance Column)
Stars: ✭ 1,097 (+1641.27%)
Mutual labels:  performance
Aws Power Tuner Ui
AWS Lambda Power Tuner UI is an open source project creating a deployable easy to use website built on a layered technology stack allowing you to optimize your Lambda functions for cost and/or performance in a data-driven way via an easy to use UI.
Stars: ✭ 52 (-17.46%)
Mutual labels:  performance
Sanic.js
JS Gotta go fast ! | Increase native JS functions performances
Stars: ✭ 50 (-20.63%)
Mutual labels:  performance
Vcprofiler
An accurate and simple tool uses KVO to measure the time cost of every view controller.
Stars: ✭ 61 (-3.17%)
Mutual labels:  performance
Phpspy
Low-overhead sampling profiler for PHP 7+
Stars: ✭ 1,105 (+1653.97%)
Mutual labels:  performance
Pc Optimization Hub
collection of various resources devoted to performance and input lag optimization
Stars: ✭ 55 (-12.7%)
Mutual labels:  performance
Ymcache
YMCache is a lightweight object caching solution for iOS and Mac OS X that is designed for highly parallel access scenarios.
Stars: ✭ 58 (-7.94%)
Mutual labels:  caching
Profimp
Python import profiler
Stars: ✭ 52 (-17.46%)
Mutual labels:  performance
Packagephobia
⚖️ Find the cost of adding a new dependency to your project
Stars: ✭ 1,110 (+1661.9%)
Mutual labels:  performance
Observer cli
Visualize Erlang/Elixir Nodes On The Command Line
Stars: ✭ 1,058 (+1579.37%)
Mutual labels:  performance
Copona
A free shopping cart system, based on OpenCart (http://www.opencart.com). An ideal alternative to Opencart, rich to develop - easy to use! Read Wiki for improvements over Opencart.
Stars: ✭ 56 (-11.11%)
Mutual labels:  performance
Mud
MUD is a layer over Overtone to make live composition more powerful and immediate.
Stars: ✭ 58 (-7.94%)
Mutual labels:  performance
Staged Streams.scala
Stars: ✭ 55 (-12.7%)
Mutual labels:  performance

EFSecondLevelCache

Entity Framework 6.x Second Level Caching Library.

Second level caching is a query cache. The results of EF commands will be stored in the cache, so that the same EF commands will retrieve their data from the cache rather than executing them against the database again.

Install via NuGet

To install EFSecondLevelCache, run the following command in the Package Manager Console:

PM> Install-Package EFSecondLevelCache

You can also view the package page on NuGet.

Usage:

1- Setting up the cache invalidation by overriding the SaveChanges method to prevent stale reads:

namespace EFSecondLevelCache.TestDataLayer.DataLayer
{
    public class SampleContext : DbContext
    {
        // public DbSet<Product> Products { get; set; }

        public SampleContext()
            : base("connectionString1")
        {
        }

        public override int SaveChanges()
        {
            return SaveAllChanges(invalidateCacheDependencies: true);
        }

        public int SaveAllChanges(bool invalidateCacheDependencies = true)
        {
            var changedEntityNames = getChangedEntityNames();
            var result = base.SaveChanges();
            if (invalidateCacheDependencies)
            {
               new EFCacheServiceProvider().InvalidateCacheDependencies(changedEntityNames);
            }
            return result;
        }

        private string[] getChangedEntityNames()
        {
            // Updated version of this method: \EFSecondLevelCache\EFSecondLevelCache.Tests\EFSecondLevelCache.TestDataLayer\DataLayer\SampleContext.cs
            return this.ChangeTracker.Entries()
                .Where(x => x.State == EntityState.Added ||
                            x.State == EntityState.Modified ||
                            x.State == EntityState.Deleted)
                .Select(x => System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(x.Entity.GetType()).FullName)
                .Distinct()
                .ToArray();
        }
    }
}

Sometimes you don't want to invalidate the cache when non important properties such as NumberOfViews are updated. In these cases, try SaveAllChanges(invalidateCacheDependencies: false), before updating the data.

2- Then to cache the results of the normal queries like:

var products = context.Products.Include(x => x.Tags).FirstOrDefault();

We can use the new Cacheable() extension method:

var products = context.Products.Include(x => x.Tags).Cacheable().FirstOrDefault(); // Async methods are supported too.

Notes:

Good candidates for query caching are global site's settings, list of public articles or comments and not frequently changed, private or specific data to each user. If a page requires authentication, its data shouldn't be cached.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].