mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -18,18 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.xwikis.sitelinks.*;
|
||||
public class Xow_cache_mgr {
|
||||
private Xowe_wiki wiki;
|
||||
private final Xowe_wiki wiki;
|
||||
public Xow_cache_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
page_cache = new Xow_page_cache(wiki);
|
||||
defn_cache = new Xow_defn_cache(wiki.Lang());
|
||||
lst_cache = new Xow_defn_cache(wiki.Lang());
|
||||
this.page_cache = new Xow_page_cache(wiki);
|
||||
this.defn_cache = new Xow_defn_cache(wiki.Lang());
|
||||
this.lst_cache = new Xow_defn_cache(wiki.Lang());
|
||||
}
|
||||
public Hash_adp Tmpl_result_cache() {return tmpl_result_cache;} private Hash_adp tmpl_result_cache = Hash_adp_bry.cs();
|
||||
public Xow_page_cache Page_cache() {return page_cache;} private Xow_page_cache page_cache;
|
||||
public Xow_defn_cache Defn_cache() {return defn_cache;} private Xow_defn_cache defn_cache;
|
||||
public Xow_defn_cache Lst_cache() {return lst_cache;} private Xow_defn_cache lst_cache;
|
||||
public Hash_adp Misc_cache() {return misc_cache;} private final Hash_adp misc_cache = Hash_adp_.New();
|
||||
public Hash_adp Tmpl_result_cache() {return tmpl_result_cache;} private final Hash_adp tmpl_result_cache = Hash_adp_bry.cs();
|
||||
public Xow_page_cache Page_cache() {return page_cache;} private Xow_page_cache page_cache;
|
||||
public Xow_defn_cache Defn_cache() {return defn_cache;} private final Xow_defn_cache defn_cache;
|
||||
public Xow_defn_cache Lst_cache() {return lst_cache;} private final Xow_defn_cache lst_cache;
|
||||
public Hash_adp Misc_cache() {return misc_cache;} private final Hash_adp misc_cache = Hash_adp_.New();
|
||||
public void Page_cache_(Xow_page_cache v) {this.page_cache = v;}
|
||||
public Keyval[] Scrib_lang_names() {
|
||||
if (scrib_lang_names == null) {
|
||||
List_adp list = List_adp_.New();
|
||||
@@ -44,10 +45,11 @@ public class Xow_cache_mgr {
|
||||
}
|
||||
return scrib_lang_names;
|
||||
}
|
||||
public void Free_mem_all() {
|
||||
public void Free_mem_all() {this.Free_mem_all(Bool_.Y);}
|
||||
public void Free_mem_all(boolean free_page_cache) {
|
||||
if (free_page_cache) page_cache.Free_mem_all();
|
||||
tmpl_result_cache.Clear();
|
||||
defn_cache.Free_mem_all();
|
||||
page_cache.Free_mem_all();
|
||||
misc_cache.Clear();
|
||||
lst_cache.Free_mem_all();
|
||||
scrib_lang_names = null;
|
||||
|
||||
@@ -24,34 +24,51 @@ public class Xow_page_cache {
|
||||
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
|
||||
return rv == null ? null : rv.Wtxt__direct();
|
||||
}
|
||||
public void Add(byte[] ttl_full_db, Xow_page_cache_itm itm) {
|
||||
cache.Add(ttl_full_db, itm);
|
||||
}
|
||||
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
synchronized (this) { // LOCK:app-level; DATE:2016-07-06
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by_bry(ttl_full_db);
|
||||
if (rv == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if (page.Db().Page().Exists()) {
|
||||
rv = new Xow_page_cache_itm(page.Ttl(), page.Db().Text().Text_bry(), page.Redirect().Itms__get_at_0th_or_null());
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by_bry(ttl_full_db);
|
||||
if (rv == Xow_page_cache_itm.Missing) return null;
|
||||
else if (rv == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if (page.Db().Page().Exists()) {
|
||||
rv = new Xow_page_cache_itm(page.Ttl(), page.Db().Text().Text_bry(), page.Redirect().Itms__get_at_0th_or_null());
|
||||
synchronized (this) { // LOCK:high-usage;DATE:2016-07-14
|
||||
cache.Add_bry_obj(ttl_full_db, rv);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
else {
|
||||
synchronized (this) { // LOCK:high-usage;DATE:2016-07-14
|
||||
cache.Add_bry_obj(ttl_full_db, Xow_page_cache_itm.Missing);
|
||||
rv = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xow_page_cache_itm Get_or_load_as_itm_2(Xoa_ttl ttl) { // NOTE: same as Get_or_load_as_itm, but handles redirects to missing pages; DATE:2016-05-02
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
synchronized (this) { // LOCK:app-level; DATE:2016-07-06
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by_bry(ttl_full_db);
|
||||
if (rv == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if ( page.Db().Page().Exists() // page exists
|
||||
|| page.Redirect().Itms__len() > 0 ) { // page redirects to missing page; note that page.Missing == true and page.Redirected_src() != null; PAGE: en.w:Shah_Rukh_Khan; DATE:2016-05-02
|
||||
rv = new Xow_page_cache_itm(page.Ttl(), page.Db().Text().Text_bry(), page.Redirect().Itms__get_at_0th_or_null());
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by_bry(ttl_full_db);
|
||||
if (rv == Xow_page_cache_itm.Missing) return null;
|
||||
else if (rv == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if ( page.Db().Page().Exists() // page exists
|
||||
|| page.Redirect().Itms__len() > 0 ) { // page redirects to missing page; note that page.Missing == true and page.Redirected_src() != null; PAGE: en.w:Shah_Rukh_Khan; DATE:2016-05-02
|
||||
rv = new Xow_page_cache_itm(page.Ttl(), page.Db().Text().Text_bry(), page.Redirect().Itms__get_at_0th_or_null());
|
||||
synchronized (this) { // LOCK:high-usage;DATE:2016-07-14
|
||||
cache.Add_bry_obj(ttl_full_db, rv);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
else {
|
||||
synchronized (this) { // LOCK:high-usage;DATE:2016-07-14
|
||||
cache.Add_bry_obj(ttl_full_db, Xow_page_cache_itm.Missing);
|
||||
rv = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Free_mem_all() {
|
||||
synchronized (this) { // LOCK:app-level; DATE:2016-07-06
|
||||
|
||||
@@ -16,7 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_page_cache_itm {
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_page_cache_itm implements Xowd_text_bry_owner {
|
||||
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt__direct, byte[] wtxt__redirect) {
|
||||
this.ttl = ttl; this.wtxt__direct = wtxt__direct; this.wtxt__redirect = wtxt__redirect;
|
||||
}
|
||||
@@ -26,5 +27,17 @@ public class Xow_page_cache_itm {
|
||||
public byte[] Wtxt__redirect_or_direct() {
|
||||
return wtxt__redirect == null ? wtxt__direct : wtxt__redirect;
|
||||
}
|
||||
|
||||
// used by xomp
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Redirect_id() {return redirect_id;} private int redirect_id;
|
||||
public void Set_text_bry_by_db(byte[] v) {this.wtxt__direct = v;}
|
||||
public void Set_page_ids(int page_id, int redirect_id) {this.page_id = page_id; this.redirect_id = redirect_id;}
|
||||
public void Set_redirect_bry(byte[] trg_wtxt) {
|
||||
this.wtxt__redirect = wtxt__direct;
|
||||
this.wtxt__direct = trg_wtxt;
|
||||
}
|
||||
|
||||
public static final Xow_page_cache_itm Null = null;
|
||||
public static final Xow_page_cache_itm Missing = new Xow_page_cache_itm(null, null, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user