logo
down
shadow

Exclude certain entities from second-level caching


Exclude certain entities from second-level caching

By : Akbar Dhedhi
Date : November 29 2020, 09:01 AM
wish of those help I found the answer in this blog post.
In order to exclude some entities, you need to create a caching policy and drive a class from CachingPolicy.
code :
class CacheConfiguration : DbConfiguration
{
    public CacheConfiguration()
    {
        var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

        AddInterceptor(transactionHandler);

        //var cachingPolicy = new CachingPolicy();
        var cachingPolicy = new myCachingPolicy();

        Loaded +=
            (sender, e) => e.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler, cachingPolicy));
    }
}

public class myCachingPolicy : CachingPolicy
{
    protected override bool CanBeCached(System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Entity.Core.Metadata.Edm.EntitySetBase> affectedEntitySets, string sql, IEnumerable<KeyValuePair<string, object>> parameters)
    {
        string[] excludedEntities = {
            "permView1",
            "permView2",
            "permView3"};

        if (affectedEntitySets.Where(x => excludedEntities.Contains(x.Table)).Any())
        {
            return false;
        }
        else
        {
            return base.CanBeCached(affectedEntitySets, sql, parameters);
        }
    }
}


Share : facebook icon twitter icon
Hibernate 2nd level cache not caching committed entities

Hibernate 2nd level cache not caching committed entities


By : solo.wags
Date : March 29 2020, 07:55 AM
I wish this help you I'm wondering if it's possible for Hibernate second level cache (we're using EHCache) to allow an application to cache an Entity that has been comitted to the DB if it knows that no other applications are modifying the DB. , State of the art POJO's in Action book talks about it
Is the second-level cache support for caching the query result exclude the entity

Is the second-level cache support for caching the query result exclude the entity


By : Frederico Duarte Fer
Date : March 29 2020, 07:55 AM
This might help you It certainly works for "new Result(...)" but I'm not 100% sure about the ResultTransformer. I cannot see a reason why it wouldn't, considering that the transformation is made after the query.
How i can making caching feature that work on application level caching through a collection to access or generate the d

How i can making caching feature that work on application level caching through a collection to access or generate the d


By : Saw Cha
Date : March 29 2020, 07:55 AM
To fix this issue You might want to check out ASP.Net Caching. It allows you to have an application wide caching store (key value collection) which exists as long as your application pool is running. Also it support expiration of inserted items.
code :
Cache.Insert("CacheItem6", "Cached Item 6",
    null, DateTime.Now.AddMinutes(1d), 
    System.Web.Caching.Cache.NoSlidingExpiration);
How to make Low-Level caching collaborate with Association caching in Rails?

How to make Low-Level caching collaborate with Association caching in Rails?


By : Emily JD
Date : March 29 2020, 07:55 AM
With these it helps There's an instance variable @association_cache in the instance of ActiveRecord::Base, which stores cached associations and determines if an association should be retrieved from the database.
We can achieve it with @association_cache like:
code :
class User < ApplicationRecord
  has_one :profile

  def cached_profile
    cache = Rails.cache.fetch(['Users', id, 'profile', updated_at.to_i]) do
      profile
    end

    reflection = self.class.reflect_on_association(:profile)
    if association_instance_get(name).nil?
      association = reflection.association_class.new(self, reflection)
      association.target = cache
      association_instance_set(:profile, association)
    end

    cache
  end
end

class Profile < ApplicationRecord
  belongs_to :user, touch: true
end
irb> u = User.take
irb> u.cached_profile # fetch the profile from the database and use the redis to cache it
  Profile Load (1.4ms) SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
irb> u.profile # use the cached version from the redis
irb> u.profile.reload # reload from the database
  Profile Load (1.4ms) SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
class User < ApplicationRecord
  include CacheAssociations

  has_one :profile
  cache_association :profile
end
NHibernate second level cache caching entities with no caching configuration

NHibernate second level cache caching entities with no caching configuration


By : Ammar Allia
Date : March 29 2020, 07:55 AM
Any of those help I had ClassConvention that was configured with second level cache. it looked as follows:
shadow
Privacy Policy - Terms - Contact Us © animezone.co