この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

OrgPartition クラス

特定のパーティションの組織キャッシュにあるキャッシュ値を管理するメソッドが含まれます。セッションキャッシュとは異なり、組織キャッシュはどのセッションにも関連付けられていないため、要求間の組織およびすべてのユーザーが使用できます。

名前空間

Cache

使用方法

このクラスは、Cache.Partition を拡張し、その非静的メソッドのすべてを継承します。キーを作成および検証するためのユーティリティメソッドはサポートされておらず、Cache.Partition 親クラスからのみコールできます。Cache.Partition メソッドの一覧は、「Partition メソッド」を参照してください。

組織のパーティションを取得するには、次のように Cache.Org.getPartition をコールし、完全修飾されたパーティション名を渡します。

1Cache.OrgPartition orgPartition = Cache.Org.getPartition('namespace.myPartition');

「パーティションメソッドのキャッシュキー形式」を参照してください。

このクラスは、サンプル Visualforce ページのコントローラーです (後続のコードサンプルを参照)。このコントローラーは、Cache.OrgPartition のメソッドを使用して特定のパーティションのキャッシュ値を管理する方法を示しています。コントローラーは Visualforce ページからパーティション名、カウンターのキー名、およびカウンターの初期値を入力します。コントローラーにはこれらの入力のデフォルト値が含まれています。Visualforce ページで [Rerender (再表示)] をクリックすると、go() メソッドが呼び出されてカウンターが 1 増加します。[Remove Key (キーを削除)] をクリックすると、カウンターキーがキャッシュから削除されます。カウンターがキャッシュに再度追加されると、カウンター値は初期値にリセッ���されます。

別のユーザーがログインしてこのサンプルを実行すると、このユーザーは前のユーザーが最後に追加または更新したキャッシュ値を取得します。たとえば、カウンター値が 5 だった場合、次のユーザーに表示されるカウンター値は増加後の 6 です。

メモ

1public class OrgPartitionController {
2  
3    // Name of a partition
4    String partitionInput = 'local.myPartition';
5    // Name of the key
6    String counterKeyInput = 'counter';
7    // Key initial value
8    Integer counterInitValue = 0;
9    // Org partition object
10    Cache.OrgPartition orgPartition;
11               
12    // Constructor of the controller for the Visualforce page. 
13    public OrgPartitionController() {  
14    }
15            
16    // Adds counter value to the cache.
17    // This method is called when the Visualforce page loads.
18    public void init() {
19        // Create the partition instance based on the partition name
20        orgPartition = getPartition();
21
22        // Create the partition instance based on the partition name
23        // given in the Visualforce page or the default value.
24        orgPartition = Cache.Org.getPartition(partitionInput);
25        
26        // Add counter to the cache with an initial value 
27        //  or increment it if it's already there.
28        if (!orgPartition.contains(counterKeyInput)) {
29            orgPartition.put(counterKeyInput, counterInitValue);
30        } else {
31            orgPartition.put(counterKeyInput, getCounter() + 1);
32        }        
33    }
34        
35    // Returns the org partition based on the partition name
36    // given in the Visualforce page or the default value.
37    private Cache.OrgPartition getPartition() {
38       if (orgPartition == null) {
39            orgPartition = Cache.Org.getPartition(partitionInput);
40       }
41       
42       return orgPartition;
43     }
44        
45
46    // Return counter from the cache.
47    public Integer getCounter() {
48        return (Integer)getPartition().get(counterKeyInput);
49    }
50    
51    // Invoked by the Submit button to save input values
52    //  supplied by the user.
53    public PageReference save() {
54        // Reset the initial key value in the cache
55        getPartition().put(counterKeyInput, counterInitValue);
56
57        return null;
58    }
59   
60    // Method invoked by the Rerender button on the Visualforce page.
61    // Updates the values of various cached values.
62    // Increases the values of counter and the MyData counter if those 
63    //   cache values are still in the cache.
64    public PageReference go() {
65        // Get the org partition object
66        orgPartition = getPartition();
67        // Increase the cached counter value or set it to 0 
68        //  if it's not cached.        
69        if (orgPartition.contains(counterKeyInput)) {
70            orgPartition.put(counterKeyInput, getCounter() + 1);
71        } else {
72            orgPartition.put(counterKeyInput, counterInitValue);
73        }        
74    
75        return null;
76    }
77    
78    // Method invoked by the Remove button on the Visualforce page.
79    // Removes the datetime cached value from the org cache.
80    public PageReference remove() {
81        getPartition().remove(counterKeyInput);
82
83        return null;
84    }
85    
86    // Get and set methods for accessing variables
87    // that correspond to the input text fields on
88    // the Visualforce page.
89    public String getPartitionInput() {
90        return partitionInput;
91    }
92    
93    public String getCounterKeyInput() {
94        return counterKeyInput;
95    }
96    
97    public Integer getCounterInitValue() {
98        return counterInitValue;
99    }
100    
101    public void setPartitionInput(String partition) {
102        this.partitionInput = partition;
103    }
104    
105    public void setCounterKeyInput(String keyName) {
106        this.counterKeyInput = keyName;
107    }
108    
109    public void setCounterInitValue(Integer counterValue) {
110        this.counterInitValue = counterValue;
111    }
112}

これは、OrgPartitionController クラスに対応する Visualforce ページです。

1<apex:page controller="OrgPartitionController" action="{!init}">
2
3    <apex:form >
4        <br/>Partition with Namespace Prefix: <apex:inputText value="{!partitionInput}"/>
5        <br/>Counter Key Name: <apex:inputText value="{!counterKeyInput}"/>
6        <br/>Counter Initial Value: <apex:inputText value="{!counterInitValue}"/>
7        <apex:commandButton action="{!save}" value="Save Key Input Values"/>
8    </apex:form>
9
10    <apex:outputPanel id="output">
11        <br/>Cached Counter: <apex:outputText value="{!counter}"/>
12    </apex:outputPanel>
13    
14    <br/>
15    <apex:form >
16        <apex:commandButton id="go" action="{!go}" value="Rerender" rerender="output"/>
17        <apex:commandButton id="remove" action="{!remove}" value="Remove Key" rerender="output"/>
18    </apex:form>
19
20</apex:page>