Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring.Caching.AspNetCache - Condition based on ReturnValue - Condition in Spring Expression Language
    primarykey
    data
    text
    <p>I use Cache Aspect with ASP.NET Cache. I need create condition based on ReturnValue.</p> <p>I simplified my problem. I use CacheResult aspect on method wich return simple POCO object.</p> <p>Here is definition:</p> <pre class="lang-cs prettyprint-override"><code>public class MyData { public string MyProperty { get; set; } } public class MyResponse { public int MyId { get; set; } public MyData [] Result { get; set; } } </code></pre> <p>I need create condition for cache - Cache result only if MyResponse.MyData.Lenght is bigger then batch limit.</p> <pre class="lang-cs prettyprint-override"><code>[CacheResult("AspNetCache", "'MyResponse.MyId=' + #id", Condition = "MyResponse.Result.Length &gt; #batchLimit")] public MyResponse GetResponse(int id, int batchLimit) { Thread.Sleep(5000); return new MyResponse { MyId = 1, Result = new MyData[] { new MyData {MyProperty = "A"}, new MyData {MyProperty = "B"}, new MyData {MyProperty = "C"}, } }; } </code></pre> <p>I tried this definition of condition:</p> <pre><code>Condition = "MyResponse.Result.Length &gt; #batchLimit" </code></pre> <p>I got this error:</p> <blockquote> <p>'MyResponse' node cannot be resolved for the specified context [Sample.MyResponse].</p> </blockquote> <p>So I tried second version:</p> <pre><code>Condition = "'MyResponse.Result.Length' &gt; #batchLimit" </code></pre> <p>Finished with error:</p> <pre><code>Cannot compare instances of [System.String] and [System.Int32] because they cannot be coerced to the same type. </code></pre> <p>I google it I can use keyword <code>ReturnValue</code> something like this:</p> <pre><code>Condition = "#ReturnValue != null" </code></pre> <p>But I don't know how I can access to <code>MyResponse.MyData.Length</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload