diff --git a/src/FluentNHibernate/Mapping/CachePart.cs b/src/FluentNHibernate/Mapping/CachePart.cs index 2f0c1094a..8c8bf890b 100644 --- a/src/FluentNHibernate/Mapping/CachePart.cs +++ b/src/FluentNHibernate/Mapping/CachePart.cs @@ -6,43 +6,32 @@ namespace FluentNHibernate.Mapping; public class CachePart(Type entityType) : ICacheMappingProvider { - readonly AttributeStore attributes = new AttributeStore(); + readonly AttributeStore attributes = new(); /// /// Sets caching to read-write /// - public CachePart ReadWrite() - { - attributes.Set("Usage", Layer.UserSupplied, "read-write"); - return this; - } + public CachePart ReadWrite() => CustomUsage("read-write"); /// /// Sets caching to non-strict read-write /// - public CachePart NonStrictReadWrite() - { - attributes.Set("Usage", Layer.UserSupplied, "nonstrict-read-write"); - return this; - } + public CachePart NonStrictReadWrite() => CustomUsage("nonstrict-read-write"); /// /// Sets caching to read-only /// - public CachePart ReadOnly() - { - attributes.Set("Usage", Layer.UserSupplied, "read-only"); - return this; - } + public CachePart ReadOnly() => CustomUsage("read-only"); /// /// Sets caching to transactional /// - public CachePart Transactional() - { - attributes.Set("Usage", Layer.UserSupplied, "transactional"); - return this; - } + public CachePart Transactional() => CustomUsage("transactional"); + + /// + /// Sets caching to never + /// + public CachePart Never() => CustomUsage("never"); /// /// Specifies a custom cache behaviour @@ -68,20 +57,12 @@ public CachePart Region(string name) /// Include all properties for caching /// /// - public CachePart IncludeAll() - { - attributes.Set("Include", Layer.UserSupplied, "all"); - return this; - } + public CachePart IncludeAll() => CustomInclude("all"); /// /// Include only non-lazy properties for caching /// - public CachePart IncludeNonLazy() - { - attributes.Set("Include", Layer.UserSupplied, "non-lazy"); - return this; - } + public CachePart IncludeNonLazy() => CustomInclude("non-lazy"); /// /// Specify a custom property inclusion strategy @@ -95,11 +76,9 @@ public CachePart CustomInclude(string custom) internal bool IsDirty => attributes.IsSpecified("Region") || attributes.IsSpecified("Usage") || attributes.IsSpecified("Include"); - CacheMapping ICacheMappingProvider.GetCacheMapping() - { - var mapping = new CacheMapping(attributes.Clone()); - mapping.ContainedEntityType = entityType; - - return mapping; - } + CacheMapping ICacheMappingProvider.GetCacheMapping() => + new(attributes.Clone()) + { + ContainedEntityType = entityType + }; }