CINXE.COM

L2 Cache | Ebean ORM

<!doctype html> <html lang="en"> <head> <title>L2 Cache | Ebean ORM</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro|Ubuntu&display=swap"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous"> <link rel="stylesheet" href="/css/reset3.css"> <link rel="stylesheet" href="/css/site3.css"> <link rel="stylesheet" href="/css/pygments3.css"> </head> <body> <div id="main"> <div id="banner"> <header> <nav id="top"> <h1 id="breadcrumb"> <a class="nav-logo" href="/"><img src="/images/logo-200.png" height="35"></a>&nbsp;&nbsp;<a href="/docs">Documentation</a><span class="sep">&nbsp;/&nbsp;</span><a href="/docs/features/">Features</a><span class="sep">&nbsp;/&nbsp;</span><span class="last">L2 Cache</span> </h1> <ul> <li><a onclick="toggleTheme();" title="switch dark light theme"><i class="fas fa-adjust"></i></a></li> </ul> </nav> </header> </div> <div class="grid grid-docs"> <aside> <nav class="side"> <ul> <li class="nav0 "> <a href="/docs/getting-started">Getting started</a> </li> <li class="nav0 "> <a href="/docs/intro">Introduction</a> </li> <li class="nav0 active"> <a class="active" href="/docs">Documentation</a> <ul> <li class="nav1 "> <a href="/docs/best-practice">Best practice</a> </li> <li class="nav1 "> <a href="/docs/query">Query</a> </li> <li class="nav1 "> <a href="/docs/persist">Persist</a> </li> <li class="nav1 "> <a href="/docs/transactions">Transactions</a> </li> <li class="nav1 "> <a href="/docs/mapping">Mapping</a> </li> <li class="nav1 "> <a href="/docs/ddl-generation">DDL & Migrations</a> </li> <li class="nav1 "> <a href="/docs/logging">Logging</a> </li> <li class="nav1 "> <a href="/docs/testing">Testing</a> </li> <li class="nav1 "> <a href="/docs/read-replicas">Read Replicas</a> </li> <li class="nav1 "> <a href="/docs/database">Database platforms</a> </li> <li class="nav1 "> <a href="/docs/multi-database">Multiple databases</a> </li> <li class="nav1 "> <a href="/docs/kotlin">Kotlin</a> </li> <li><a href="/docs/tuning">Tuning</a></li> <li class="nav1 active"> <a class="active" href="/docs/features">Features</a> <ul class="nav"> <li class="active"> <a class="active" href="/docs/features/l2cache">L2 Cache</a> <ul class="nav"> <li > <a href="/docs/features/l2cache">Overview</a> </li> <li > <a href="/docs/features/l2cache/bean-cache">Bean caching</a> </li> <li > <a href="/docs/features/l2cache/query-cache">Query caching</a> </li> <li class="active"> <a class="active" href="/docs/features/l2cache/invalidation">Invalidation</a> <ul class="nav nav-scroll"> <li><a href="#bean">Bean IUD</a></li> <li><a href="#table">Table IUD / Bulk updates</a></li> <li><a href="#explicit">Explicit</a></li> </ul> </li> <li > <a href="/docs/features/l2cache/hazelcast">Hazelcast</a> </li> <li > <a href="/docs/features/l2cache/apache-ignite">Apache Ignite</a> </li> </ul> </li> <li > <a href="/docs/features/elasticsearch">Elasticsearch</a> </li> <li > <a href="/docs/features/json-in-db">@DbJson</a> </li> <li > <a href="/docs/features/softdelete">Soft Delete</a> </li> <li > <a href="/docs/features/encryption">Encryption</a> </li> <li > <a href="/docs/features/who">@WhoModified / @WhoCreated</a> </li> <li > <a href="/docs/features/history">SQL2011 History</a> </li> <li > <a href="/docs/features/changelog">ChangeLog</a> </li> <li > <a href="/docs/features/readauditing">Read auditing</a> </li> <li > <a href="/docs/features/eventlistening">Event Listening</a> </li> </ul> </li> </ul> </li> <li class="nav0 "> <a href="/support">Getting help</a> </li> <li class="nav0 "> <a target="_blank" href="/apidoc/13">API Javadoc</a> </li> <li class="nav0 "> <a href="/videos">Videos</a> </li> <li class="nav0 "> <a href="/docs/upgrading">Upgrading</a> </li> <li class="nav0 "> <a href="/releases">Releases</a> </li> </ul> </nav> </aside> <article> <form action="https://www.google.com/search" method="get" class="inline-form"> <input type="hidden" name="as_sitesearch" value="ebean.io"> <div id="page-search"> <div class="input-group"> <input class="frm" name="q" id="searchinput" type="text" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off"> <div class="input-group-btn"> <button class="frm" type="submit"><i class="fas fa-search"></i></button> </div> </div> <div id="page-search-results" style="display: none;"> <ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul> </div> </div> </form> <h2 id="bean">Bean IUD invalidation</h2> <p> Cache invalidation is automatically provided for persisted beans. The cache invalidation is processed by bean type and id value. </p> <h4>Cluster message</h4> <p> The message sent around the cluster contains the bean type and 3 lists of ids - a list of id values for inserted, updated and deleted beans. </p> <h4>L2 query cache</h4> <ul> <li><code>Inserts, updates or deletes:</code> Invalidate the entire L2 query cache for the bean type</li> </ul> <p> For any bean persist event invalidates the entire related L2 query cache for the associated bean type. For example, saving a customer bean invalidates the entire L2 query cache for the Customer bean type. </p> <h4>L2 bean cache</h4> <ul> <li><code>Inserts:</code> Do not effect the L2 bean cache</li> <li><code>Updates:</code> An entry is updated with changes</li> <li><code>Deletes:</code> An entry is removed from the L2 bean cache based on the id value</li> </ul> <h2 id="table">Table IUD invalidation (Bulk updates)</h2> <p> Bulk insert, update or delete events are processed by table. For a given table the bean types that depend on that table are determined and then for each bean type the L2 bean cache and L2 query cache are invalidated as necessary. </p> <h4>Cluster message</h4> <p> The message sent around the cluster contains the table name and boolean flags for insert, update and delete. </p> <h4>L2 query cache</h4> <ul> <li><code>Inserts, updates or deletes:</code> Invalidate the entire L2 query cache for the related bean type</li> </ul> <p> For any bulk statements (bulk table insert, update or delete statement) the entire L2 query cache is invalidated for the associated bean type. For example, a bulk update of the customer table invalidates the entire L2 query cache for the Customer bean type. </p> <h4>L2 bean cache</h4> <ul> <li><code>Inserts:</code> Do not effect the L2 bean cache</li> <li><code>Updates:</code> Invalidate the entire L2 bean cache for the related bean type</li> <li><code>Deletes:</code> Invalidate the entire L2 bean cache for the related bean type</li> </ul> <h2 id="explicit">Explicit invalidation</h2> <p> We can perform explicit invalidation using application code. We want to do this when data is modified externally to Ebean. For example, data is updated by other frameworks, JDBC code etc. For this case we want to explicitly invalidate parts of the L2 cache. </p> <h4>Using externalModification()</h4> <div class="syntax java"><div class="highlight"><pre><span></span><span class="c1">// inform Ebean that some rows have been inserted and updated</span> <span class="c1">// on the country table.</span> <span class="c1">// ... Ebean will invalidate the appropriate caches</span> <span class="kt">boolean</span> <span class="n">inserts</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="kt">boolean</span> <span class="n">updates</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="kt">boolean</span> <span class="n">deletes</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span> <span class="n">DB</span><span class="o">.</span><span class="na">externalModification</span><span class="o">(</span><span class="s">&quot;country&quot;</span><span class="o">,</span> <span class="n">inserts</span><span class="o">,</span> <span class="n">updates</span><span class="o">,</span> <span class="n">deletes</span><span class="o">);</span> </pre></div> </div> <h4>Using ServerCacheManager</h4> <p> ServerCacheManager also provides explicit API for clearing caches. </p> <div class="syntax java"><div class="highlight"><pre><span></span><span class="c1">// clearAll() caches via the ServerCacheManager ...</span> <span class="n">ServerCacheManager</span> <span class="n">cacheManager</span> <span class="o">=</span> <span class="n">database</span><span class="o">.</span><span class="na">cacheManager</span><span class="o">();</span> <span class="c1">// Clear all the caches on the default/primary EbeanServer</span> <span class="n">cacheManager</span><span class="o">.</span><span class="na">clearAll</span><span class="o">();</span> <span class="c1">// clear both the bean and query cache</span> <span class="c1">// for Country beans ...</span> <span class="n">cacheManager</span><span class="o">.</span><span class="na">clear</span><span class="o">(</span><span class="n">Country</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> </pre></div> </div> </article> </div> </div> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="/js/site3.js"></script> <script src="/js/search3.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-75181644-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-75181644-1'); </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10