14
14
using System . Data . Common ;
15
15
using NHibernate . Connection ;
16
16
using NHibernate . Engine ;
17
+ using NHibernate . Impl ;
17
18
using NHibernate . Metadata ;
18
19
using NHibernate . Stat ;
19
20
20
21
namespace NHibernate
21
22
{
22
23
using System . Threading . Tasks ;
23
24
using System . Threading ;
25
+ public static partial class SessionFactoryExtension
26
+ {
27
+ /// <summary>
28
+ /// Evict all entries from the process-level cache. This method occurs outside
29
+ /// of any transaction; it performs an immediate "hard" remove, so does not respect
30
+ /// any transaction isolation semantics of the usage strategy. Use with care.
31
+ /// </summary>
32
+ /// <param name="factory">The session factory.</param>
33
+ /// <param name="persistentClasses">The classes of the entities to evict.</param>
34
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
35
+ public static async Task EvictAsync ( this ISessionFactory factory , IEnumerable < System . Type > persistentClasses , CancellationToken cancellationToken = default ( CancellationToken ) )
36
+ {
37
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
38
+ if ( factory is SessionFactoryImpl sfi )
39
+ {
40
+ await ( sfi . EvictAsync ( persistentClasses , cancellationToken ) ) . ConfigureAwait ( false ) ;
41
+ }
42
+ else
43
+ {
44
+ if ( persistentClasses == null )
45
+ throw new ArgumentNullException ( nameof ( persistentClasses ) ) ;
46
+ foreach ( var @class in persistentClasses )
47
+ {
48
+ await ( factory . EvictAsync ( @class , cancellationToken ) ) . ConfigureAwait ( false ) ;
49
+ }
50
+ }
51
+ }
52
+
53
+ /// <summary>
54
+ /// Evict all entries from the second-level cache. This method occurs outside
55
+ /// of any transaction; it performs an immediate "hard" remove, so does not respect
56
+ /// any transaction isolation semantics of the usage strategy. Use with care.
57
+ /// </summary>
58
+ /// <param name="factory">The session factory.</param>
59
+ /// <param name="entityNames">The names of the entities to evict.</param>
60
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
61
+ public static async Task EvictEntityAsync ( this ISessionFactory factory , IEnumerable < string > entityNames , CancellationToken cancellationToken = default ( CancellationToken ) )
62
+ {
63
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
64
+ if ( factory is SessionFactoryImpl sfi )
65
+ {
66
+ await ( sfi . EvictEntityAsync ( entityNames , cancellationToken ) ) . ConfigureAwait ( false ) ;
67
+ }
68
+ else
69
+ {
70
+ if ( entityNames == null )
71
+ throw new ArgumentNullException ( nameof ( entityNames ) ) ;
72
+ foreach ( var name in entityNames )
73
+ {
74
+ await ( factory . EvictEntityAsync ( name , cancellationToken ) ) . ConfigureAwait ( false ) ;
75
+ }
76
+ }
77
+ }
78
+
79
+ /// <summary>
80
+ /// Evict all entries from the process-level cache. This method occurs outside
81
+ /// of any transaction; it performs an immediate "hard" remove, so does not respect
82
+ /// any transaction isolation semantics of the usage strategy. Use with care.
83
+ /// </summary>
84
+ /// <param name="factory">The session factory.</param>
85
+ /// <param name="roleNames">The names of the collections to evict.</param>
86
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
87
+ public static async Task EvictCollectionAsync ( this ISessionFactory factory , IEnumerable < string > roleNames , CancellationToken cancellationToken = default ( CancellationToken ) )
88
+ {
89
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
90
+ if ( factory is SessionFactoryImpl sfi )
91
+ {
92
+ await ( sfi . EvictCollectionAsync ( roleNames , cancellationToken ) ) . ConfigureAwait ( false ) ;
93
+ }
94
+ else
95
+ {
96
+ if ( roleNames == null )
97
+ throw new ArgumentNullException ( nameof ( roleNames ) ) ;
98
+ foreach ( var role in roleNames )
99
+ {
100
+ await ( factory . EvictCollectionAsync ( role , cancellationToken ) ) . ConfigureAwait ( false ) ;
101
+ }
102
+ }
103
+ }
104
+ }
105
+
24
106
public partial interface ISessionFactory : IDisposable
25
107
{
26
108
@@ -42,15 +124,6 @@ public partial interface ISessionFactory : IDisposable
42
124
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
43
125
Task EvictAsync ( System . Type persistentClass , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
44
126
45
- /// <summary>
46
- /// Evict all entries from the process-level cache. This method occurs outside
47
- /// of any transaction; it performs an immediate "hard" remove, so does not respect
48
- /// any transaction isolation semantics of the usage strategy. Use with care.
49
- /// </summary>
50
- /// <param name="persistentClasses"></param>
51
- /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
52
- Task EvictAsync ( IEnumerable < System . Type > persistentClasses , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
53
-
54
127
/// <summary>
55
128
/// Evict an entry from the process-level cache. This method occurs outside
56
129
/// of any transaction; it performs an immediate "hard" remove, so does not respect
@@ -68,13 +141,6 @@ public partial interface ISessionFactory : IDisposable
68
141
/// </summary>
69
142
Task EvictEntityAsync ( string entityName , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
70
143
71
- /// <summary>
72
- /// Evict all entries from the second-level cache. This method occurs outside
73
- /// of any transaction; it performs an immediate "hard" remove, so does not respect
74
- /// any transaction isolation semantics of the usage strategy. Use with care.
75
- /// </summary>
76
- Task EvictEntityAsync ( IEnumerable < string > entityNames , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
77
-
78
144
/// <summary>
79
145
/// Evict an entry from the second-level cache. This method occurs outside
80
146
/// of any transaction; it performs an immediate "hard" remove, so does not respect
@@ -91,15 +157,6 @@ public partial interface ISessionFactory : IDisposable
91
157
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
92
158
Task EvictCollectionAsync ( string roleName , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
93
159
94
- /// <summary>
95
- /// Evict all entries from the process-level cache. This method occurs outside
96
- /// of any transaction; it performs an immediate "hard" remove, so does not respect
97
- /// any transaction isolation semantics of the usage strategy. Use with care.
98
- /// </summary>
99
- /// <param name="roleNames"></param>
100
- /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
101
- Task EvictCollectionAsync ( IEnumerable < string > roleNames , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
102
-
103
160
/// <summary>
104
161
/// Evict an entry from the process-level cache. This method occurs outside
105
162
/// of any transaction; it performs an immediate "hard" remove, so does not respect
0 commit comments