Skip to content

Commit d956d26

Browse files
committed
Add cache usage option "never"
Fixes #528
1 parent 363709d commit d956d26

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed
Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
using System;
22
using FluentNHibernate.Mapping.Providers;
33
using FluentNHibernate.MappingModel;
4+
using NHibernate.Mapping.ByCode;
45

56
namespace FluentNHibernate.Mapping;
67

78
public class CachePart(Type entityType) : ICacheMappingProvider
89
{
9-
readonly AttributeStore attributes = new AttributeStore();
10+
readonly AttributeStore attributes = new();
1011

1112
/// <summary>
1213
/// Sets caching to read-write
1314
/// </summary>
14-
public CachePart ReadWrite()
15-
{
16-
attributes.Set("Usage", Layer.UserSupplied, "read-write");
17-
return this;
18-
}
15+
public CachePart ReadWrite() => CustomUsage("read-write");
1916

2017
/// <summary>
2118
/// Sets caching to non-strict read-write
2219
/// </summary>
23-
public CachePart NonStrictReadWrite()
24-
{
25-
attributes.Set("Usage", Layer.UserSupplied, "nonstrict-read-write");
26-
return this;
27-
}
20+
public CachePart NonStrictReadWrite() => CustomUsage("nonstrict-read-write");
2821

2922
/// <summary>
3023
/// Sets caching to read-only
3124
/// </summary>
32-
public CachePart ReadOnly()
33-
{
34-
attributes.Set("Usage", Layer.UserSupplied, "read-only");
35-
return this;
36-
}
25+
public CachePart ReadOnly() => CustomUsage("read-only");
3726

3827
/// <summary>
3928
/// Sets caching to transactional
4029
/// </summary>
41-
public CachePart Transactional()
42-
{
43-
attributes.Set("Usage", Layer.UserSupplied, "transactional");
44-
return this;
45-
}
30+
public CachePart Transactional() => CustomUsage("transactional");
31+
32+
/// <summary>
33+
/// Sets caching to never
34+
/// </summary>
35+
public CachePart Never() => CustomUsage("never");
4636

4737
/// <summary>
4838
/// Specifies a custom cache behaviour
@@ -68,20 +58,12 @@ public CachePart Region(string name)
6858
/// Include all properties for caching
6959
/// </summary>
7060
/// <returns></returns>
71-
public CachePart IncludeAll()
72-
{
73-
attributes.Set("Include", Layer.UserSupplied, "all");
74-
return this;
75-
}
61+
public CachePart IncludeAll() => CustomInclude("all");
7662

7763
/// <summary>
7864
/// Include only non-lazy properties for caching
7965
/// </summary>
80-
public CachePart IncludeNonLazy()
81-
{
82-
attributes.Set("Include", Layer.UserSupplied, "non-lazy");
83-
return this;
84-
}
66+
public CachePart IncludeNonLazy() => CustomInclude("non-lazy");
8567

8668
/// <summary>
8769
/// Specify a custom property inclusion strategy
@@ -95,11 +77,9 @@ public CachePart CustomInclude(string custom)
9577

9678
internal bool IsDirty => attributes.IsSpecified("Region") || attributes.IsSpecified("Usage") || attributes.IsSpecified("Include");
9779

98-
CacheMapping ICacheMappingProvider.GetCacheMapping()
99-
{
100-
var mapping = new CacheMapping(attributes.Clone());
101-
mapping.ContainedEntityType = entityType;
102-
103-
return mapping;
104-
}
80+
CacheMapping ICacheMappingProvider.GetCacheMapping() =>
81+
new(attributes.Clone())
82+
{
83+
ContainedEntityType = entityType
84+
};
10585
}

0 commit comments

Comments
 (0)