mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
64
400_xowa/src/gplx/xowa/wikis/caches/Xow_cache_mgr.java
Normal file
64
400_xowa/src/gplx/xowa/wikis/caches/Xow_cache_mgr.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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_cache_mgr {
|
||||
private 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());
|
||||
}
|
||||
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 KeyVal[] Scrib_lang_names() {
|
||||
if (scrib_lang_names == null) {
|
||||
List_adp list = List_adp_.new_();
|
||||
Cfg_nde_root root = wiki.Appe().Lang_mgr().Groups();
|
||||
int len = root.Root_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Cfg_nde_obj nde = root.Root_get_at(i);
|
||||
Scrib_lang_names_grps(list, nde);
|
||||
}
|
||||
scrib_lang_names = (KeyVal[])list.To_ary(KeyVal.class);
|
||||
}
|
||||
return scrib_lang_names;
|
||||
} private static KeyVal[] scrib_lang_names;
|
||||
private void Scrib_lang_names_grps(List_adp list, Cfg_nde_obj nde) {
|
||||
int len = nde.Nde_subs_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Cfg_nde_obj lang_nde = nde.Nde_subs_get_at(i);
|
||||
if (lang_nde.Nde_typ_is_grp())
|
||||
Scrib_lang_names_grps(list, lang_nde);
|
||||
else {
|
||||
Xoac_lang_itm lang_itm = (Xoac_lang_itm)lang_nde;
|
||||
KeyVal kv = KeyVal_.new_(String_.new_u8(lang_itm.Key_bry()), String_.new_u8(lang_itm.Local_name_bry()));
|
||||
list.Add(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Free_mem_all() {
|
||||
tmpl_result_cache.Clear();
|
||||
defn_cache.Free_mem_all();
|
||||
page_cache.Free_mem_all();
|
||||
lst_cache.Free_mem_all();
|
||||
scrib_lang_names = null;
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/wikis/caches/Xow_defn_cache.java
Normal file
37
400_xowa/src/gplx/xowa/wikis/caches/Xow_defn_cache.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.*;
|
||||
import gplx.intl.*;
|
||||
public class Xow_defn_cache { // stores compiled Xot_defn
|
||||
private Xol_lang lang; // needed to lowercase names;
|
||||
private Bry_bfr upper_1st_bfr = Bry_bfr.reset_(255);
|
||||
private Gfo_cache_mgr cache = new Gfo_cache_mgr().Max_size_(64 * 1024 * 1024).Reduce_by_(32 * 1024 * 1024);
|
||||
public Xow_defn_cache(Xol_lang lang) {this.lang = lang;}
|
||||
public Xot_defn Get_by_key(byte[] name) {return (Xot_defn)cache.Get_by_key(name);}
|
||||
public void Free_mem_all() {cache.Clear();}
|
||||
public void Free_mem_some() {cache.Reduce_recent();}
|
||||
public void Add(Xot_defn defn, byte case_match) {
|
||||
byte[] name = defn.Name();
|
||||
int cache_size = defn.Cache_size(); // OBSOLETE: * 2 b/c it has src and root;
|
||||
cache.Add_replace(name, defn, cache_size);
|
||||
if (case_match == Xow_ns_case_.Id_1st) {
|
||||
name = lang.Case_mgr().Case_build_1st_upper(upper_1st_bfr, name, 0, name.length);
|
||||
cache.Add_replace(name, defn, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/wikis/caches/Xow_page_cache.java
Normal file
40
400_xowa/src/gplx/xowa/wikis/caches/Xow_page_cache.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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 {
|
||||
private Xowe_wiki wiki;
|
||||
private Hash_adp_bry cache = Hash_adp_bry.cs_(); // NOTE: wiki titles are not case-sensitive when ns is "1st-letter" (EX: w:earth an w:Earth); in these cases, two entries will be stored
|
||||
public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;}
|
||||
public byte[] Get_or_load_as_src(Xoa_ttl ttl) {
|
||||
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
|
||||
return rv == null ? null : rv.Wtxt();
|
||||
}
|
||||
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
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().Get_page(ttl, true); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if (!page.Missing()) {
|
||||
rv = new Xow_page_cache_itm(page.Ttl(), page.Data_raw(), page.Redirected_src());
|
||||
cache.Add_bry_obj(ttl_full_db, rv);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Free_mem_all() {cache.Clear();}
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/wikis/caches/Xow_page_cache_itm.java
Normal file
27
400_xowa/src/gplx/xowa/wikis/caches/Xow_page_cache_itm.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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 {
|
||||
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt, byte[] redirected_src_wtxt) {
|
||||
this.ttl = ttl; this.wtxt = wtxt; this.redirected_src_wtxt = redirected_src_wtxt;
|
||||
}
|
||||
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
|
||||
public byte[] Wtxt() {return wtxt;} private byte[] wtxt;
|
||||
public byte[] Redirected_src_wtxt() {return redirected_src_wtxt;} private byte[] redirected_src_wtxt;
|
||||
public static final Xow_page_cache_itm Null = null;
|
||||
}
|
||||
Reference in New Issue
Block a user